Frequently yes, magnesium deficiency is a major cause of sudden, painful leg cramps at night. Boosting magnesium through diet and supplements helps.