The score was tied 1-1 in the sixth when Donnie Murphy led off with a single against Pirates starter Francisco Liriano and Junior Lake followed with a walk -- bringing up McDonald, who belted a pitch into the left-field bleachers for a three-run shot.
Jake Arrieta (4-2) yielded one run on four hits over six innings, walking two and striking out one to collect the victory.
Kevin Gregg recorded his 33rd save despite allowing a run in the ninth for Chicago, which avoided a three-game sweep.
Liriano (16-8) absorbed the loss, surrendering four runs on eight hits over five innings. The Pirates -- who have already clinched a post-season berth -- fell three games behind National League Central-leading St. Louis with four games remaining.
Campus cop fatally shoots Texas student during traffic stop
Police: Sword-wielding man demanded free tacos