BackgroundFew studies have assessed the correlation between coexisting mental disorders in participants with diabetes mellitus (DM) and the risk of heart failure (HF). Herein, we conducted a cohort study to determine the association between the accumulation of mental disorders in participants with DM and the risk of HF.MethodsThe Korean National Health Insurance Service records were assessed. 2,447,386 adults with DM who underwent health screening between 2009 and 2012 were analyzed. Participants with major depressive disorder, bipolar disorder, schizophrenia, insomnia, or anxiety disorders were included. In addition, participants were categorized based on the number of coexisting mental disorders. Each participant was followed until December 2018 or until the onset of HF. Cox proportional hazard modelling with confounding factors adjustment was conducted. In addition, a competing risk analysis was conducted. Subgroup analysis assessed the impact of clinical variables on the association between the accumulation of mental disorders and the risk of HF.ResultsThe median follow-up duration was 7.09 years. The accumulation of mental disorders was associated with a risk of HF (zero mental disorder (0), reference; 1 mental disorder, adjusted hazard ratio (aHR): 1.222, 95% confidence intervals (CI): 1.207–1.237; 2 mental disorders, aHR: 1.426, CI: 1.403–1.448; ≥3 mental disorders, aHR: 1.667, CI: 1.632–1.70. In the subgroup analysis, the strength of association was the strongest in the younger age group (< 40 years, 1 mental disorder, aHR 1.301, CI 1.143–1.481; ≥2 mental disorders, aHR 2.683, CI 2.257–3.190; 40–64 years, 1 mental disorder, aHR 1.289, CI 1.265–1.314; ≥2 mental disorders, aHR 1.762, CI 1.724–1.801; ≥65 years, 1 mental disorder, aHR 1.164, CI 1.145–1.183; ≥2 mental disorders, aHR 1.353, CI 1.330–1.377; Pinter<0.001). In addition, income, BMI, hypertension, chronic kidney disease, history of cardiovascular disease, insulin use, and duration of DM showed significant interactions.ConclusionsComorbid mental disorders in participants with DM are associated with an increased risk of HF. In addition, the association was stronger in a younger age group. Participants with DM and mental disorders should be monitored with increased frequency for signs of HF; for which they have a higher risk than the general population.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12933-023-01809-4.