There is controversy over the role of magnesium in the etiology of migraine headaches. We aimed to evaluate and compare serum levels of magnesium between healthy individuals and those with migraine headaches during migraine attacks and between attacks to evaluate the role of magnesium in the etiology of migraine headaches. Forty patients with migraine headaches and 40 healthy individuals were enrolled in this matched case–control study. Malnutrition, digestive system disorders, history of smoking, drug abuse, and history of medications use were recorded at baseline. The pain scores of patients were measured and recorded based on a 10 cm visual analog scale. Subsequently, blood samples were collected at 8–10 in the morning to determine serum levels of magnesium. Analysis of variance, χ2-test, and conditional logistic regression were used for data analysis. There were no significant differences in demographic data between the two groups. There were significant differences in magnesium serum levels between the three groups (1.09±0.2 mg/dl during migraine headaches; 1.95±0.3 mg/dl between the attacks; and 1.3±0.4 mh/dl in the control group; P<0.0001). Odds of acute migraine headaches increased 35.3 times (odds ratio=35.3; 95% confidence interval: 12.4–95.2; P=0.001) when serum levels of magnesium reached below the normal level. The odds in patients who are not in the acute attack phase were 6.9 folds higher (odds ratio=6.9; 95% confidence interval: 1.3–2.1; P=0.02). The serum level of magnesium is an independent factor for migraine headaches and patients with migraine have lower serum levels of magnesium during the migraine attacks and between the attacks compared with healthy individuals.