Inflammation has been proposed as a mechanism linking cardiometabolic diseases (CMDs) to increased risk of dementia. However, whether an anti-inflammatory diet can support brain and cognitive health among people with CMDs is unclear. To examine CMD status and dietary inflammatory potential in association with dementia risk and brain magnetic resonance imaging (MRI) measures using joint effect analysis. The UK Biobank is an ongoing community-based cohort study with baseline assessments conducted between March 13, 2006, and October 1, 2010. The present study included 84 342 dementia-free older adults (≥60 years), who were followed up until January 20, 2022 (maximum, 15 years). A subsample (n = 8917) underwent brain MRI scans between May 2, 2014, and March 13, 2020. Baseline CMDs (including type 2 diabetes, heart disease, and stroke) were ascertained from medical records. Dietary Inflammatory Index scores (anti-inflammatory [≤-1.5 points], neutral [>-1.5 to <0.5 points], or proinflammatory [≥0.5 points]) were calculated from participants' average intake of 31 nutrients, assessed up to 5 times using the Oxford WebQ, a web-based, 24-hour dietary assessment. Incident dementia was identified through linkage to medical records. Regional brain volumes were collected from brain MRI scans. The study included 84 342 participants (mean [SD] age, 64.1 [2.9] years; 43 220 [51.2%] female). At baseline, 14 079 (16.7%) had at least 1 CMD. Over a median follow-up of 12.4 (IQR, 11.8-13.1) years, 1559 individuals (1.9%) developed dementia. With the use of joint effect analysis, the hazard ratio of dementia was 2.38 (95% CI, 1.93-2.93) for people with CMDs and a proinflammatory diet and 1.65 (95% CI, 1.36-2.00) for those with CMDs and an anti-inflammatory diet (reference: CMD-free, anti-inflammatory diet). Dementia risk was 31% lower (hazard ratio, 0.69; 95% CI, 0.55-0.88; P = .003) among people with CMDs and an anti-inflammatory diet. On brain MRI, participants with CMDs and an anti-inflammatory diet compared with a proinflammatory diet additionally had significantly larger gray matter volume (β = -0.15; 95% CI, -0.24 to -0.06 vs β = -0.27; 95% CI, -0.38 to -0.16) and smaller white matter hyperintensity volume (β = 0.05; 95% CI, -0.04 to 0.14 vs β = 0.16; 95% CI, 0.05-0.27). In this cohort study, people with CMDs and an anti-inflammatory compared with proinflammatory diet had a significantly lower hazard ratio of dementia, larger gray matter volume, and smaller white matter hyperintensity volume.