ABSTRACT: AIMS/HYPOTHESIS:Previous studies have found an association between serum magnesium and incident diabetes; however, this association may be due to reverse causation, whereby diabetes may induce urinary magnesium loss. In contrast, in prediabetes (defined as impaired fasting glucose), serum glucose levels are below the threshold for urinary magnesium wasting and, hence, unlikely to influence serum magnesium levels. Thus, to study the directionality of the association between serum magnesium levels and diabetes, we investigated its association with prediabetes. We also investigated whether magnesium-regulating genes influence diabetes risk through serum magnesium levels. Additionally, we quantified the effect of insulin resistance in the association between serum magnesium levels and diabetes risk. METHODS:Within the population-based Rotterdam Study, we used Cox models, adjusted for age, sex, lifestyle factors, comorbidities, kidney function, serum levels of electrolytes and diuretic use, to study the association between serum magnesium and prediabetes/diabetes. In addition, we performed two mediation analyses: (1) to study if common genetic variation in eight magnesium-regulating genes influence diabetes risk through serum magnesium levels; and (2) to quantify the proportion of the effect of serum magnesium levels on diabetes that is mediated through insulin resistance (quantified by HOMA-IR). RESULTS:A total of 8555 participants (mean age, 64.7 years; median follow-up, 5.7 years) with normal glucose levels (mean?±?SD: 5.46?±?0.58 mmol/l) at baseline were included. A 0.1 mmol/l decrease in serum magnesium level was associated with an increase in diabetes risk (HR 1.18 [95% CI 1.04, 1.33]), confirming findings from previous studies. Of interest, a similar association was found between serum magnesium levels and prediabetes risk (HR 1.12 [95% CI 1.01, 1.25]). Genetic variation in CLDN19, CNNM2, FXYD2, SLC41A2, and TRPM6 significantly influenced diabetes risk (p?