Objective: This study measured the effectiveness of magnesium sulfate during and after coronary artery bypass grafting (CABG) on postoperative pain and respiratory functions, and compared it with 2 other well-known and widely used analgesic agents: codeine and diclofenac, a nonsteroidal anti-inflammatory drug (NSAID). Design: Prospective unblinded study. Setting: Single institution. Participants: Patients undergoing CABG. Interventions: Patients were divided into 3 groups. In group A (n = 50), intraoperative magnesium sulfate, 2 g/70 kg, was infused intravenously and was continued during the first 3 days postoperatively. In group B (n = 50), codeine, 60 mg/70 kg, was given orally 4 times a day for 3 days. In group C (n = 50), diclofenac sodium, 75 mg, was given orally twice a day for 3 days. Main Results: On the first postoperative day the visual analog scale (VAS) score was greater than 5 in all groups. On the second day the VAS score was greater than 5 in groups B and C, and was less than 5 in group A. On the third day the VAS score was less than 5 in all groups. During the first 2 postoperative days the need for morphine was significantly less in group A than in the other 2 groups. Preoperative respiratory function tests (forced expiratory volume in 1 second [FEV1], forced vital capacity [FVC], and FEV1/FVC) were similar in each group. The FEV1, FVC, and FEV1/FVC values on the postoperative first, second, and third days were significantly higher in group A. Conclusions: Magnesium sulfate can be a beneficial adjuvant therapy for pain after CABG. In this respect, especially in patients with respiratory problems or intolerance to NSAIDs, magnesium sulfate can be a better choice than NSAIDs and opioids.