James McDonald pitched into the eighth 1 victory over the game series.
McDonald (9-7) allowed one run on three hits and three walks while fanning six through 7 1/3 innings in Pittsburgh's third win in four games.
"His pitch count was efficient throughout," Pirates manager Clint Hurdle said about McDonald. "They scratched that one run across. It was a really good outing for him."
Joel Hanrahan put the game-tying runs in scoring position in the ninth, but closed out the game to earn his 35th save of the year.
Henry Sosa (2-3) went six full frames, surrendering two runs on six hits and three walks to take the loss.
Jose Altuve had a run-scoring triple for the Astros, who dropped their fourth straight game.
Hanrahan walked Carlos Lee to start the ninth and then allowed a base hit to Jimmy Paredes to put the game-tying runs on the bases. Matt Downs came up next and lifted a base hit into shallow center field. The hit would have loaded the bases, but Paredes rounded too far around second, thinking Chris Johnson, who was pinch-running for Lee, was going to score and Paredes was tagged out between second and third.
Downs advanced to second on the play, making the game a hit away from a tie, but J.B. Shuck flied out to left to end the game.
Houston struck first in the third inning. Sosa walked with one out and came around to score on Altuve's two-out triple into right. Altuve was stranded at third, though, as J.D. Martinez struck out swinging to end the inning.
"It was one of those games that was just miserable," Martinez said. "It's just one of those games we hope to put behind us."
Pittsburgh took the lead for good in the fourth. Andrew McCutchen led off the frame with an infield single and Derrek Lee was hit by a pitch. Two batters later, Ryan Doumit sent a double into left-center field, scoring McCutchen. Josh Harrison followed with a base hit up the middle to bring home Lee.
The Pirates would then load the bases with one out when Ronny Cedeno worked a walk, but would not push another run across the plate as McDonald hit a ball back to the mound that Sosa turned into an inning-ending, 1-2-3 double play.
Grilli got a force at third on Altuve's comebacker to the mound and caught Martinez looking on a fastball on the inside corner to end the inning and keep it a 2-1 game.
Lee then gave the Pirates a little cushion in the bottom of the eighth with an opposite field, solo home run over the right-field wall.
The game was delayed 56 minutes at the start because of rain...Pirates right fielder Jose Tabata left the game in the fourth inning due to discomfort in his left wrist...Houston's Carlos Lee went 0-for-3 to end his season-high 14- game hit streak...McDonald improved to 2-1 in six games -- five starts -- against Houston...The win was the 599th of Hurdle's career...Houston had a man thrown out at the plate in the sixth inning.