McDonald had six strikeouts and allowed three hits, three walks and a run. That run came in the third when he walked opposing pitcher Henry Sosa, and Jose Altuve hit a triple to the right-field wall.
The Pirates, though, took a two-run lead in the fourth on an RBI double by Ryan Doumit and an up-the-middle RBI single by Josh Harrison. They added another in the eighth on a solo homer by Derrek Lee.
Joel Hanrahan picked up his 35th save of the season despite loading the bases in the ninth.
The Pirates are now 65-76, four games behind the Cincinnati Reds for third place in the NL Central. The Astros have lost four in a row and are 47-94.
For more on the Pirates, check out Bucs Dugout.