The Pirates and Cardinals, having fallen behind the hot Cincinnati Reds in the National League Central race, are both battling for a wild-card position.
Pittsburgh, which won its second straight but has just three victories in its last nine outings, moved two games in front of the Cardinals for second place in the division.
McDonald (11-5) gave up only two hits and won for the first time since July 18. This was his fifth start since that victory.
Those two runs were given up by Jake Westbrook, who allowed six hits and three walks in 7 2/3 innings to absorb the loss.
Notable deaths of 2014 [PHOTOS]
Michael Sam cut from the Dallas Cowboys