Background Depression has been reported to increase the risk of subsequently developing dementia, but the nature of this relation remains to be elucidated. Depression can be a prodrome/manifestation of dementia or an early risk factor, and the effect may differ according to depression subtypes. Our aim was to study the association between early-onset depression and different depression subtypes, and the later occurrence of dementia. Methods We conducted a cohort study including 322 subjects with depression, recruited between 1977 and 1984. A comparison cohort (non-exposed) was recruited retrospectively, to include 322 subjects admitted at the same hospital for routine surgery (appendicectomy or cholecystectomy), at the same period as the depressed cohort. Subjects were contacted again between 2009 and 2014, to assess their dementia status. We computed the risk for dementia in subjects with early onset depression and quantified the association between different depression subtypes (namely melancholic, anxious, and psychotic) and dementia. Results The odds of dementia were increased by 2.90 times (95% C.I. 1.61-5.21; p<0.0001) for the depressed cohort when compared to the surgical cohort. When the analysis was restricted to patients younger than 45 years old at baseline, the odds for dementia in the depressed cohort were also significantly higher when compared to the surgical cohort (8.53; 95% C.I. 2.40-30.16). In the multivariate Cox analysis, subjects having depression with melancholic features had an increased risk for developing dementia compared to those without melancholic features (HR=3.64; 95% C.I. 1.78-11.26; p=0.025). Limitations About 59% of the participants with depression and 53% of those non-exposed were lost during follow up. The inclusion of biological biomarkers would strengthen the results. The sample included a low number of bipolar patients. Conclusions These results support depression as an early risk factor for dementia. Depression with melancholic features was found as an important risk factor for dementia, playing a main role in the relation between these disorders.