AimsTo investigate the causal role of serum magnesium and calcium in epilepsy or any of its subtypes through Mendelian randomization (MR) approach.MethodsSingle nucleotide polymorphisms (SNPs) associated with serum magnesium and calcium were used as the instrumental variables. MR analyses were performed using the summary‐level data for epilepsy extracted from International League Against Epilepsy Consortium (15,212 cases and 29,677 controls) to obtain the causal estimates. The analyses were replicated using FinnGen data (7224 epilepsy cases and 208,845 controls), and a meta‐analysis was then conducted.ResultsThe result of combined analyses showed that higher serum magnesium concentrations was associated with a reduced risk of overall epilepsy (odds ratios [OR] = 0.28, 95% confidence interval [CI], 0.12–0.62, p = 0.002). In ILAE, higher serum magnesium was suggestively associated with reduced risks of focal epilepsy (OR = 0.25, 95% CI 0.10–0.62, p = 0.003). However, the results cannot be repeated in sensitivity analyses. As for serum calcium, the results did not reach statistical significance with overall epilepsy (OR = 0.60, 95% CI, 0.31–1.17, p = 0.134). However, genetically predicted serum calcium concentrations showed an inverse association with risk of generalized epilepsy (OR = 0.35, 95% CI, 0.17–0.74, p = 0.006).ConclusionThe current MR analysis did not support a causal relationship between serum magnesium and epilepsy, but showed a causally negative association between genetically determined serum calcium and generalized epilepsy.