Magnesium is a mineral that is essential for healthy muscles, nerves, bones and blood sugar levels. If you don't get enough magnesium in your diet over a long time, you may be at a higher risk of health problems such as heart attack, stroke, diabetes or osteoporosis.