"That was a long time coming right there," manager Brad Mills said.
Brett Wallace opened the inning with a full-count walk, making way for Greene, pinch running. Greene, in his first day with the club, jumped for second base on the first pitch to Pearce and raced to third when the ball hopped past catcher Jonathan Lucroy.
With nobody out, Pearce tied the game with his single up the middle. He raced to second after center fielder Carlos Gomez took his time getting to the ball.
"For us to give ourselves chances to win every day, we can't really miss doing little things," Bogusevic said. "It's things like that. It's things like working walks in a long at bat, getting guys over, getting guys in with less than two outs. It won a game for us today."
Moore nearly won the game with a deep fly to center, but Gomez made a great catch to keep the Brewers alive. Pearce moved to third on the catch, but didn't stay there long, scoring on Bogusevic's hit on a 3-1 fastball from Axford.
"I don't know how many times I can say the same words over. I'm frustrated," Axford said. "I've been feeling really good. Still felt good out there tonight. Just, leadoff walk, wild pitch, fell behind some guys. If I don't walk the guy, it's a different story."
In their five-game losing streak heading into Friday, the Astros had three one-run losses. They haven't won an extra-inning game this season.
"We've been in so many of these games and we haven't been able to pull it out, and tonight it was just a great feeling," Pearce said. "It's something this team definitely needed."
Starter Mark Rogers, making his fifth career start, held Houston hitless through four. After walking leadoff hitter Jose Altuve in the first inning, Rogers retired 12 straight.
Moore reached on a bunt single in the fifth inning for the Astros' first hit. Bogusevic followed with a line drive single and Carlos Corporan brought Moore home with a single through the right side, giving the Astros their first run.
Corporan hit a solo homer in the eighth off reliever Francisco Rodriguez to bring the Astros within a run. The catcher sprinted around the bases like he was racing somebody and gave a big fist pump before entering the dugout.
"He does it with a lot of emotion, a lot of passion for not just himself, but for the whole team," Mills said.
Starter Bud Norris recovered from some tough luck in the first two innings.
The right-hander gave up runs in both the first and second inning, spotting the Brewers a 2-0 lead. He settled down after that, getting double plays to end the third and fourth and retiring the side in order in the fifth and sixth. In the seventh, Rickie Weeks hit his third leadoff double of the evening and scored on a Jean Segura single.
The right-hander threw 99 pitches, 69 for strikes. He didn't issue a walk for the first time since June 6 and said he's feeling better on the mound.
"This team battled hard," Norris said. "I'm going out there to keep it close and these guys came back and battled back. One in the eighth and two in the ninth, that's a nice way to win a ballgame."
Fernando Rodriguez and Wilton Lopez pitched scoreless innings in the eighth and ninth, paving the way for the Astros' long-awaited walk-off win.
The Astros don't want to mess with their newfound mojo on Saturday and requested to wear the same throwback jerseys they wore in Friday's game.
"This is a moment you can't train for," Pearce said. "When something like this happens, it's always special. It doesn't matter what your record is."
Clark Goble is an associate reporter for MLB.com.
This story was not subject to the approval of Major League Baseball or its clubs.