This study investigates the associations between adherence to Mediterranean diet (MedDiet) or MIND diet and overall/specific cancer risks, exploring the mediating effects of metabolites using UK Biobank data. Results show significant negative associations of both diets with overall and several specific cancers. A sequential analysis identified 10 metabolites associated with cancer risk, mediating the relationship between diet and cancer risk. These findings highlight the complex interplay between diet, metabolites, and cancer development.