PurposeTo examine the association between dietary magnesium (Mg) intake and brain volumes and white matter lesions (WMLs) in middle to early old age.MethodsParticipants (aged 40–73 years) from UK Biobank (n = 6001) were included and stratified by sex. Dietary Mg was measured using an online computerised 24 h recall questionnaire to estimate daily Mg intake. Latent class analysis and hierarchical linear regression models were performed to investigate the association between baseline dietary Mg, Mg trajectories, and brain volumes and WMLs. Associations between baseline Mg, and baseline blood pressure (BP) measures, and baseline Mg, Mg trajectories and BP changes (between baseline and wave 2) were also investigated to assess whether BP mediates the link between Mg intake and brain health. All analyses controlled for health and socio-demographic covariates. Possible interactions between menopausal status and Mg trajectories in predicting brain volumes and WMLs were also investigated.ResultsOn average, higher baseline dietary Mg intake was associated with larger brain volumes (gray matter [GM]: 0.001% [SE = 0.0003]; left hippocampus [LHC]: 0.0013% [SE = 0.0006]; and right hippocampus [RHC]: 0.0023% [SE = 0.0006]) in both men and women. Latent class analysis of Mg intake revealed three classes: “high-decreasing” (men = 3.2%, women = 1.9%), “low-increasing” (men = 1.09%, women = 1.62%), and “stable normal” (men = 95.71%, women = 96.51%). In women, only the “high-decreasing” trajectory was significantly associated with larger brain volumes (GM: 1.17%, [SE = 0.58]; and RHC: 2.79% [SE = 1.11]) compared to the “normal-stable”, the “low-increasing” trajectory was associated with smaller brain volumes (GM: − 1.67%, [SE = 0.30]; white matter [WM]: − 0.85% [SE = 0.42]; LHC: − 2.43% [SE = 0.59]; and RHC: − 1.50% [SE = 0.57]) and larger WMLs (1.6% [SE = 0.53]). Associations between Mg and BP measures were mostly non-significant. Furthermore, the observed neuroprotective effect of higher dietary Mg intake in the “high-decreasing” trajectory appears to be greater in post-menopausal than pre-menopausal women.ConclusionsHigher dietary Mg intake is related to better brain health in the general population, and particularly in women.