We analyzed the role of magnesium sulfate (MgSO 4 ) supplementation during cardiopulmonary bypass in pediatric patients undergoing cardiac surgery, assessing the incidence of hypomagnesemia and the incidence of junctional ectopic tachycardia.We performed a randomized, double-blind, controlled trial in 99 children. MgSO 4 or placebo was administered during the rewarming phase of cardiopulmonary bypass: group 1, placebo group (29 patients); group 2, 25 mg/kg of MgSO 4 (30 patients); and group 3, 50 mg/kg of MgSO 4 (40 patients).At the time of admission to the cardiac intensive care unit, groups receiving MgSO 4 had significantly greater levels of ionized magnesium (group 1, 0.51 ± 0.07; group 2, 0.57 ± 0.09; group 3, 0.59 ± 0.09). Hypomagnesemia before bypass was common (75%–86.2%) and not significantly different among the groups. The proportion of hypomagnesemia decreased significantly at admission to the cardiac intensive care unit in groups receiving MgSO 4 (group 1, 77.8%; group 2, 63%; group 3, 47.4%). Patients receiving placebo (group 1) had a significantly greater occurrence of junctional ectopic tachycardia than groups receiving MgSO 4 (group 1, n = 5 [17.9%]; group 2, n = 2 [6.7%]; group 3, n = 0 [0%]). Age (<1 month), Aristotle score (>4), and history of cardiac failure were associated with junctional ectopic tachycardia. None of the patients with those characteristics in group 3 had junctional ectopic tachycardia. No association was found between study groups and the Pediatric Risk of Mortality score or length of stay in the cardiac intensive care unit.Supplementation with MgSO 4 during cardiopulmonary bypass seems to reduce the incidence of hypomagnesemia and junctional ectopic tachycardia at admission to the cardiac intensive care unit. This effect seems to be dose related.