Astros reliever Wesley Wright, who alternated between the mound and right field in the eighth inning, got the first out in the ninth before making way for rookie Rhiner Cruz, filling the closer role with Francisco Cordero out with a sprained toe. Cruz faced three batters and didn't retire any -- the third, Casey McGehee, walked on a tight 3-2 pitch that flirted with the strike zone.
Manager Brad Mills then called upon Xavier Cedeno, who got Starling Marte to hit a sacrifice fly to center that would have been the final out had the pitch to McGehee been called a strike. Instead, pinch-runner Jordy Mercer, who advanced to third on McGahee's walk, scored to tie the game.
The bad luck continued for the Astros moments later when a wild pitch from Cedeno brought pinch-runner Drew Sutton to the plate and gave the Pirates a one-run lead.
"Having the lead in three of the last four games is tough, there's no doubt," Mills said. "And it beats up on everybody, but these guys have been battling so well all the way through and I'm sure they're going to come out tomorrow and do the same thing."
The Astros tied a club record with their 11th consecutive loss, but they remain determined as ever.
"We have to," Johnson said. "If you get down, it's just going to get worse. We've got to keep battling."
In the home half of the ninth, J.D. Martinez singled off closer Joel Hanrahan and pinch runner Jordan Schafer stole second, but Hanrahan finished off his 31st save by striking out Justin Maxwell and getting Brian Bogusevic to pop out.
"We're there. We're going to get through it," Astros starter Jordan Lyles said. "Every day we come to the park, we don't have any doubts in our minds, no second-guessing ourselves. We enjoy being around each other and we feel we can get on a hot streak and turn it around."
Mills said he decided to bring Cedeno in because Cruz wasn't throwing strikes. He couldn't send out Wilton Lopez -- arguably the Astros' top reliever -- because he used him in the eighth inning to face dangerous hitter Andrew McCutchen. The center fielder doubled.
"We were going back and forth on that and Lopie had had such good success against McCutchen and we were trying to get to that ninth inning," Mills said. "As we went through this, I knew what it was going to come down to, but we were in a situation where we had to get McCutchen to try to get to the ninth inning."
The Astros were in a position to win the game after Martinez's RBI single in the seventh gave them the lead.
The red-hot Johnson led off the inning with a triple off reliever Jared Hughes that rolled up Tal's Hill in center field. Scott Moore grounded out to first before Martinez singled through a drawn-in infield to put the Astros ahead, 5-4.
Johnson finished 3-for-4 with a double, triple, home run and walk. He had a shot at the cycle, needing a single during his at-bat in the eighth inning, but he struck out.
Lyles, the youngest starting pitcher in the National League at 21 years and 281 days old, went six innings and gave up four runs. He struck out a season-high eight batters, as many as he did in his last three starts total. The eight strikeouts also tied for Lyles' career high.
Lyles retired the first 10 batters in order, getting five groundouts, four strikeouts and a fly out. Alex Presley's solo homer in the fourth inning brought the Pirates within two. McCutchen followed with a double, but Lyles stranded him at third.
He wasn't entirely satisfied with his performance.
"I think, in general, everyone has to step up their game a little bit and it starts with starting pitching," Lyles said. "I have to do a better job myself. Like tonight, I have to do a better job when they put up four runs for me."
The Astros scored four runs in the first four innings, jumping out to a 4-1 lead. Johnson hit a solo homer in the third. In his last eight games, Johnson is batting .484 (15-for-31) with two homers and six RBIs.
Ben Francisco homered in the fourth, his first homer with the Astros. Umpires reviewed the call but confirmed the ruling.