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.
Pregnant Mila Kunis wins 'Best Villain' at MTV Movie Awards
'Happy' fan videos make Pharrell cry [VIDEO]