Abstract Background Coronavirus disease 2019 (COVID-19) is associated with an increased risk of myocardial infarction (MI). Small studies suggest that MI in patients with recent COVID-19 may have a distinct clinical course and a worse prognosis, compared to MI without recent COVID-19. Whether previous COVID-19 vaccination modifies the clinical course of MI after recent COVID-19 is also unknown. Purpose To compare mortality in people with MI with and without recent COVID-19, and to examine the impact of previous COVID-19 vaccination. Methods Using Danish health registries, we conducted a nationwide population-based cohort study comprising all adults (≥18 years) with a first-time MI between 26 May 2020 and 9 March 2022. We excluded patients with <1 year of residence in Denmark prior to their MI. The exposure was recent COVID-19 defined by a positive SARS-CoV-2 PCR test ≤90 days before MI. We followed the patients for 30 days from the date of their MI admission until death (if any), or emigration, whichever came first. We used Cox proportional-hazards regression to compute hazard ratios (HRs) for death within 30 days after MI. Using propensity-score balancing of confounders with stabilised inverse probability weighting, we adjusted for differences in age, sex, DANCAMI comorbidity burden, use of selected medications, and calendar period between MI patients with and without recent COVID-19. We stratified by COVID-19 vaccination status. Results Of 11,919 included patients with MI, 332 patients had COVID-19 within 90 days before MI. The COVID-19 exposed patients were characterised by a larger proportion of males and COVID-19 vaccinations, lower age, and a longer median time from first COVID-19 vaccination to MI compared to the COVID-19 unexposed patients. 34 of the patients with recent COVID-19 (10.2%) and 702 of the patients without recent COVID-19 (6.1%) died within 30 days after their MI, resulting in a crude HR of 1.71 with a 95% confidence interval (CI) of 1.21–2.42 for the patients with recent COVID-19. After adjusting by stabilised inverse probability weighting, this HR further increased to 2.08 (95% CI: 1.23–3.52). Previous COVID-19 vaccination modified this association with a three-fold increased mortality in unvaccinated MI patients with recent COVID-19, while the mortality HR associated with recent COVID-19 was close to one in patients who were previously COVID-19 vaccinated. Conclusion Patients with recent COVID-19 had increased short-term mortality after MI, but only if unvaccinated.