HOUSTON - James McDonald was hoping to end a recent string of bad outings on Sunday.
Instead, the Pittsburgh right-hander's struggles continued and the Houston Astros ended a team-record 12-game losing streak with a 9-5 victory over the Pirates.
In five innings, McDonald (10-5) gave up five runs and six hits with a career-high seven walks - matching his total of free passes for the month of June in 30 2/3 innings. McDonald has lost consecutive decisions for the first time this season and is 1-2 with an 8.71 ERA in his last four starts.
"The last couple outings have been rough," McDonald said. "I think every year I've pitched, I've been in the same situation where you have to fight your way out of a couple of rough starts. I've got some work ahead of me."
It was the fourth consecutive start where McDonald allowed five runs or more after holding opponents to four runs or fewer in his first 17 outings.
Pirates manager Clint Hurdle said McDonald worked hard, but his delivery and release point were inconsistent.
"This guy was lights out," Hurdle said. "This is his second full season in the major leagues. This isn't really that weird in the context of what goes on, he's hit a wall. He was hard to hit, but then you're getting to a point where you're just trying to throw strikes and you're not painting locations like we've seen him do."
Houston's Lucas Harrell (8-7) allowed two runs and five hits in 5 2-3 inning for his first victory in five starts since a six-hit shutout against San Diego on June 27.
The Astros' 12-game skid matched Kansas City (April 11-24) and the Chicago Cubs (May 15-27) for the longest in the major leagues this year. It broke the previous franchise record of 11, set from Aug. 17-28, 1995, and matched over the end of the 2009 season and start of 2010, according to STATS LLC.
Hours after Houston traded third baseman Chris Johnson to Arizona - the Astros' fifth deal of the month - Jordan Schafer homered and drove in three runs. Houston, a big league-worst 35-68, won for only the third time in 28 games but has traded players with salaries totaling $49 million.
J.D. Martinez's sacrifice fly put Houston ahead in the third, but Pittsburgh's Garrett Jones hit a two-run homer in the fourth, a drive into the right-field upper deck. The Pirates have homered in a team-record 19 straight road games and have an NL-high 72 home runs on the road this season.
"He threw a fastball and I just reacted," Jones said. "I got the good part of the bat on it and let the rest take care of itself. It felt really good off the bat."
Schafer's two-run homer gave the Astros the lead for good in the bottom half, and Martinez tripled in the fifth on a ball misplayed by Jones in right and then scored on Scott Moore's single. After catcher Michael McKenry made a diving tag at the plate on Moore on a ball in front of the plate, Schafer hit an RBI groundout for a 5-2 lead.
Moore singled in a run in the sixth off Kevin Correia. Neil Walker's RBI double off Fernardo Rodriguez cut the gap to 6-3 in the seventh before Marwin Gonzalez hit a three-run double down the left-field line with two outs. Gonzalez had three hits and three RBIs.
Chuckie Fick threw a run-scoring wild pitch in the ninth, and Walker hit a sacrifice fly off Xavier Cedeno.
Game notes: Pittsburgh has 108 home runs this season, one more than last year. The Pirates have homered in 17 of their last 19 games.