Introduction: Magnesium is a vital intracellular cation crucial for over 320 enzymatic reactions related to energy metabolism, musculoskeletal function, and nucleic acid synthesis and plays a pivotal role in human physiology. This study aimed to explore the prevalence of dysmagnesemia in patients with diabetes mellitus and evaluate its correlations with glycemic control, medication use, and diabetic complications. Methods: A cross-sectional study was conducted at Sultan Qaboos University Hospital, including 316 patients aged 18 years or older with diabetes mellitus. Data included demographics, medical history, medications, and biochemical parameters. Serum total magnesium concentrations were measured, and dysmagnesemia was defined as magnesium ≤ 0.69 mmol/L for hypomagnesemia and ≥1.01 mmol/L for hypermagnesemia. Results: The prevalence of hypomagnesemia in patients with diabetes was 17.1% (95% CI: 13.3–21.7%), and hypermagnesemia was 4.1% (95% CI: 2.4–7.0%). Females were significantly overrepresented in the hypomagnesemia group, while the hypermagnesemia group showed a higher prevalence of hypertension, retinopathy, an increased albumin/creatinine ratio, chronic kidney disease (CKD), elevated creatinine levels, and a lower adjusted calcium concentration. The multinominal logistic regression exhibited that the female sex and higher serum-adjusted calcium were independent risk factors of hypomagnesemia. In contrast, the presence of hypertension, higher levels of albumin/creatinine ratio, and stage 5 CKD were independent risk factors of hypermagnesemia. Conclusions: Hypomagnesemia was common among patients with diabetes mellitus; however, hypermagnesemia was associated with microvascular complications.