evidence: Although myocarditis and pericarditis were not observed as adverse events in coronavirus disease 2019 (COVID-19) vaccine trials, there have been numerous reports of suspected cases following vaccination in the general population. We undertook a self-controlled case series study of people aged 16 or older vaccinated for COVID-19 in England between 1 December 2020 and 24 August 2021 to investigate hospital admission or death from myocarditis, pericarditis and cardiac arrhythmias in the 1–28 days following adenovirus (ChAdOx1, n = 20,615,911) or messenger RNA-based (BNT162b2, n = 16,993,389; mRNA-1273, n = 1,006,191) vaccines or a severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) positive test (n = 3,028,867). We found increased risks of myocarditis associated with the first dose of ChAdOx1 and BNT162b2 vaccines and the first and second doses of the mRNA-1273 vaccine over the 1–28 days postvaccination period, and after a SARS-CoV-2 positive test. [...] In summary, this population-based study quantifies for the first time the risk of several rare cardiac adverse events associated with three COVID-19 vaccines as well as SARS-CoV-2 infection. Vaccination for SARS-CoV-2 in adults was associated with a small increase in the risk of myocarditis within a week of receiving the first dose of both adenovirus and mRNA vaccines, and after the second dose of both mRNA vaccines. By contrast, SARS-CoV-2 infection was associated with a substantial increase in the risk of hospitalization or death from myocarditis, pericarditis and cardiac arrhythmia.