Objective: To assess the association between specific heart diseases and suicide. Design: Nationwide retrospective cohort study. Participants: A total of 7 298 002 individuals (3 640 632 males and 3 657 370 females) aged ≥15 years and living in Denmark during 1980–2016. Main outcome measures: Incidence rate ratios (IRR) with 95% confidence intervals. In multivariate analysis, we adjust for sex, period, age group, living status, income level, Charlson Comorbidity Index, psychiatric disorders prior to heart disease and self-harm prior to heart disease. Results: Excess suicide rate ratios were found for following disorders: heart failure (IRR: 1.48; 95% CI: 1.38–1.58); cardiomyopathy (IRR: 1.41; 95% CI: 1.16–1.70); acute myocardial infarction (IRR: 1.28; 95% CI: 1.21–1.36); cardiac arrest with successful resuscitation (IRR: 4.75; 95% CI: 3.57–6.33); atrial fibrillation and flutter (IRR: 1.42; 95% CI: 1.32–1.52); angina pectoris (IRR: 1.19; 95% CI: 1.12–1.26); and ventricular tachycardia (IRR: 1.53; 95% CI: 1.20–1.94). A higher rate of suicide was noted during the first 6 months after the diagnosis of heart failure (IRR: 2.38; 95% CI: 2.04–2.79); acute myocardial infarction (IRR: 2.24; 95% CI: 1.89–2.66); atrial fibrillation and flutter (IRR: 2.70; 95% CI: 2.30–3.18); and angina pectoris (IRR: 1.83; 95% CI: 1.53–2.19) when compared to later. Conclusion: Several specific disorders were found to be associated with elevated rates of suicide. Additionally, we found temporal associations with higher suicide rates in the first time after diagnosis. Our results underscore the importance of being attentive towards psychological distress in individuals with heart disease.