Previous studies indicate an increased long-term risk for incident cancer and cancer-specific mortality in patients undergoing cardiac surgery. We compared the risk for incident cancer and cancer-specific mortality between patients and matched control subjects from the general population. All patients (n=127,119) undergoing first-time coronary artery and/or heart valve surgery in Sweden during 1997-2020 were included in a population-based observational cohort study based on individual data from the SWEDEHEART registry and four other mandatory national registries. The patients were compared with an age-, sex-, and place of residence-matched control population (n=415,287) using multivariable Cox proportional hazards regression models adjusted for baseline characteristics, co-morbidities, and socioeconomic factors. A propensity score-matched analysis with 81,522 well-balanced pairs was also performed. Median follow-up was 9.2 (range 0-24) years. A total of 31,361/127,119 (24.7%) of the patients and 102,959/415,287 (24.8%) control subjects developed cancer during follow-up. The crude event rates were 2.75 and 2.83 per 100 person-years, respectively. The adjusted risk for cancer and cancer-specific mortality was lower in patients (adjusted hazard ratios 0.86 (95% confidence interval (CI) 0.85-0.88) and 0.64 (95% CI 0.62-0.65), respectively). The propensity score-matched analysis showed similar results (hazard ratios 0.88 (95% CI 0.86-0.90) and 0.65 (95% CI 0.63 to 0.68), respectively). The results were consistent in subgroups based on sex, age, and comorbidities. Patients that underwent cardiac surgery have lower risk for cancer and cancer-specific mortality than matched control subjects.