BackgroundFew studies have suggested that patients with myocardial infarction (MI) may be at increased risk of cancer, but further large register-based studies are needed to evaluate this subject. The aim of this study was to assess the incident rates of cancer and death by history of MI, and whether an MI is independently associated with cancer in a large cohort study.MethodAll Danish residents aged 30–99 in 1996 without prior cancer or MI were included and were followed until 2012. Patients were grouped according to incident MI during follow-up. Incidence rates (IR) of cancer and death in individuals with and without MI and incidence rate ratios (IRR, using multivariable Poisson regression analyses) of cancer associated with an MI were calculated.ResultsOf 2,871,168 individuals, 122,275 developed an MI during follow-up, 11,375 subsequently developed cancer (9.3%, IR 19.1/1000 person-years) and 65,225 died (53.3%, IR 106.0/1000 person-years). In the reference population, 372,397 developed cancer (13.0%, IR 9.3/1000 person-years) and 753,767 died (26.3%, IR 18.2/1000 person-years). Compared to the reference population, higher IRs of cancer and death were observed in all age groups (30–54, 55–69 and 70–99 years) and time since an MI (0–1, 1–5 and 5–17 years) in the MI population. MI was associated with an increased risk of overall cancer (IRR 1.14, 95% CI 1.10–1.19) after adjusting for age, sex and calendar year, also when additionally adjusting for chronic obstructive pulmonary disease, hypertension, dyslipidemia, diabetes and socioeconomic status (IRR 1.08, 95% CI 1.03–1.13), but not after further adjustment for the first 6 months post-MI (IRR 1.00, 95% CI 0.96–1.05).ConclusionPatients after an MI have increased incidence of cancer, which may be explained by mutual risk, occult cancers and increased surveillance. Focus on risk factor management to reduce cancer and MI is warranted.Electronic supplementary materialThe online version of this article (10.1186/s12872-018-0932-z) contains supplementary material, which is available to authorized users.