To investigate age- and sex-specific DNA methylation alterations related to cancer risk and survival, we used matched case–control studies of colorectal (n = 835), gastric (n = 170), kidney (n = 143), lung (n = 332), prostate (n = 869) and urothelial (n = 428) cancers, and mature B-cell lymphoma (n = 438). Linear mixed-effects models were conducted to identify age-, sex- and age-by-sex-associated methylation markers using a discovery (controls)-replication (cases) strategy. Replication was further examined using summary statistics from Generation Scotland (GS). Associations between replicated markers and risk of and survival from cancer were assessed using conditional logistic regression and Cox models (hazard ratios (HR)), respectively. We found 32,659, 23,141 and 48 CpGs with replicated associations for age, sex and age-by-sex, respectively. The replication rates for these CpGs using GS summary data were 94%, 86% and 91%, respectively. Significant associations for cancer risk and survival were identified at some individual age-related CpGs. Opposite to previous findings using epigenetic clocks, there was a strong negative trend in the association between epigenetic drift and risk of colorectal cancer. Methylation at two CpGs overlapping TMEM49 and ARX genes was associated with survival of overall (HR = 0.91, p = 7.7 × 10−4) and colorectal (HR = 1.52, p = 1.8 × 10−4) cancer, respectively, with significant age-by-sex interaction. Our results may provide markers for cancer early detection and prognosis prediction.