Background Depression is associated with an increased risk of dementia. However, short follow-up times and lack of adjustment for familial factors in previous studies could influence this association. The purpose of the present study was to investigate the association between depression and subsequent dementia, while controlling for familial factors and with a followup of over 35 years. Methods and findings Two cohorts were formed from all individuals aged 50 years or older living in Sweden as of 31 December 2005 (n = 3,341,010). The Swedish National Patient Register was searched from 1964 through 2016 to identify diagnosis of depression and dementia. In the first cohort, individuals diagnosed with depression (n = 119,386) were matched 1:1 with controls without depression diagnosis. The second cohort was a sibling cohort (n = 50,644) consisting of same-sex full sibling pairs with discordant depression status. In the population matched cohort study, a total of 9,802 individuals were diagnosed with dementia during a mean follow-up time of 10.41 (range 0-35) years (5.5% of those diagnosed with depression and 2.6% of those without depression diagnosis (adjusted odds ratio [aOR] 2.47, 95% CI 2.35-2.58; p < 0.001), with a stronger association for vascular dementia (aOR 2.68, 95% CI 2.44-2.95; p < 0.001) than for Alzheimer disease (aOR 1.79, 95% CI 1.68-1.92; p < 0.001). The association with dementia diagnosis was strongest in the first 6 months after depression diagnosis (aOR 15.20, 95% CI 11.85-19.50; p < 0.001), then decreased rapidly but persisted over follow-up of more than 20 years (aOR 1.58, 95% CI 1.27-1.98; p < 0.001). Also in the sibling cohort, the association was strongest in the first 6 months (aOR 20.85, 95% CI 9.63-45.12; p < 0.001), then decreased rapidly but persisted over follow-up of more than 20 years (aOR 2.33, 95% CI 1.32-4.11; p < 0.001). The adjusted models included sex, age at baseline, citizenship, civil status, household income, and diagnoses at baseline. The main