Based on the Finnish nationwide register, the study included 62,555 people aged 65+ with dementia diagnosed in 2017–2020 and 312,772 controls without dementia, matched by age, sex, year of birth and period. They identified 29 hospital-treated diseases with a prevalence of ≥1% before dementia, associated with an increased risk of dementia (adjusted frequency ratio ≥1.20, p<0.04), of which 27 were non-infectious (mental, behavioral, digestive, endocrine, cardiometabolic, neurological, eye diseases and injuries) and 2 were infectious (cystitis, bacterial infection of unspecified site). 47% of dementia cases (29,376) had at least one of these diseases before diagnosis. The association of cystitis with dementia had a frequency ratio of 1.22 (95% CI [1.17–1.27]; p<0.001) before adjustment and 1.19 (95% CI [1.14–1.24]; p<0.001) after adjustment for comorbidities; for bacterial infections of unspecified site, 1.21 (95% CI [1.16–1.28]; p<0.001) and 1.19 (95% CI [1.13–1.25]; p<0.001). The increased risk remained independent of comorbidities in subgroups according to gender, education and was stronger with earlier onset of dementia. Conclusion: Serious infections are an independent risk factor for dementia, unaffected by non-infectious comorbidities.