First is the article by Dr. Rowe that points to the depletion of magnesium during extended exercise. Here is the key point:
“Magnesium ion deficiency is a further possible complication of long exercise, some deficiency may still be present 3 months later. The mechanism is not clear, but may be partly due to removal of free magnesium ions from the circulation by chelation with catecholamine-induced free fatty acids. Exposure to heat also contributes to magnesium ion deficiency. This deficiency increases release of catecholamines, increases the potential for coronary vasospasm, potentiates the vasoconstrictor action of catecholamines, and in combination with catecholamine infusions or stress sensitises animals to myocardial necrosis. Magnesium ion deficiency may precipitate a hypercoagulable state, which may be aggravated by residual increased catecholamines (conducive to platelet aggregation and thrombin generation), the increase in catecholamine concentration may persist until the second day after a marathon. It is noteworthy that in a group of 20 patients with vasospastic (variant) angina Goto et al  showed that almost half had magnesium ion deficiency that is often unrecognised.”
But, it is not just running long distances that may deplete magnesium. I sometimes have a bit of a down mood a day or two after a very hard workout. So much so that I make sure to cut off my exercise even when I feel quite strong and energetic.
It turns out that intense exercise, not necessary of long duration, shifts magnesium to cells from the blood stream. This might well result in sequestering of magnesium in muscle with a loss of blood-borne magnesium reaching the brain. That almost seem to be enough to induce a mood shift because magnesium is so important to energy metabolism. A reduction of ATP in the brain must have implications for mood.
The shift from blood to muscle cells is understandable when you realize how important magnesium is to various enzymes that regulate energy production, particularly those that split ATP bonds. The muscles need magnesium to fuel their intense activity and capture it from the blood stream, with a loss to the brain. I really like these competitive allocation stories between organs. Metabolism IS economics.
The increase of magnesium excretion was related to the intensity of the exercise in Deuster et al. Magnesium homeostasis during high-intensity anaerobic exercise in men. Journal Appl. Physiol. 62(2): 545-550,(1987) . It was also related to the amount of lactic acid formed, a measure of intensity.
Here is a slightly long paragraph on the results: “First, it has been demonstrated that prolonged heavy exercise is accompanied by transient impairment of the renal concentrating mechanisms (24). Thus local renal handling of Mg might be disturbed. On the other hand, several hormones, such as aldosterone, antidiuretic hormone (ADH), and thyroid hormones, are reported to cause hypermagnesuria by reducing tubular reabsorption of Mg (8, 12, 14, 20, 22). Both aldosterone and ADH, hormones that regulate renal handling of Mg, are increased by strenuous exercise (11, 12, 18, 20, 26) and may remain elevated for as long as 14 h after the exercise is terminated (18). This could result in an increased Mg excretion. Alternatively, the exercise-induced rise in blood lactic acid causes an elevation in plasma phosphorus (1, 21) and metabolic acidosis. A metabolic acidosis has been shown to cause magnesuria by reducing renal tubular reabsorption of Mg (8). Thus these and other metabolic alterations are potential mechanisms that might accelerate urinary Mg loss.”