Abstract Background High-level plasma 25-hydroxyvitamin D [25(OH)D] has been associated with lower colorectal cancer incidence and mortality. Considering evidence indicating immunomodulatory effects of vitamin D, we hypothesised that survival benefits from high systemic vitamin D level might be stronger for colorectal carcinoma with lower immune response to tumour. Methods Using 869 colon and rectal cancer cases within the Nurses' Health Study and Health Professionals Follow-up Study, we assessed the prognostic association of postdiagnosis 25(OH)D score [derived from diet and lifestyle variables to predict plasma 25(OH)D level] in strata of levels of histopathologic lymphocytic reaction. The Cox proportional hazards regression model was adjusted for potential confounders, including microsatellite instability, CpG island methylator phenotype, LINE-1 methylation, PTGS2 (cyclooxygenase-2) expression and KRAS , BRAF and PIK3CA mutations. Results The association of postdiagnosis 25(OH)D score with colorectal cancer-specific mortality differed by levels of peritumoural lymphocytic reaction (p interaction = 0.001). Multivariable-adjusted mortality hazard ratios for a quintile-unit increase of 25(OH)D score were 0.69 [95% confidence interval (CI), 0.54–0.89] in cases with negative/low peritumoural lymphocytic reaction, 1.08 (95% CI, 0.93–1.26) in cases with intermediate peritumoural reaction and 1.25 (95% CI, 0.75–2.09) in cases with high peritumoural reaction. The survival association of the 25(OH)D score did not significantly differ by Crohn's-like lymphoid reaction, intratumoural periglandular reaction or tumour-infiltrating lymphocytes. Conclusions The association between the 25(OH)D score and colorectal cancer survival is stronger for carcinomas with lower peritumoural lymphocytic reaction. Our results suggesting interactive effects of vitamin D and immune response may contribute to personalised dietary and lifestyle intervention strategies. Highlights • The survival association of vitamin D is stronger in cancer with fewer lymphocytes. • Vitamin D and peritumoural lymphocytes interact to modify cancer progression. • Vitamin D may exert anti-tumour immune-enhancing effects. • Peritumoural lymphocytic reaction may be a biomarker for benefits from vitamin D. • Our data support immunomodulatory lifestyle interventions for cancer patients. [ABSTRACT FROM AUTHOR]