Updated

Down four runs in the ninth inning against one of the shakiest bullpens in baseball, the Houston Astros were confident they could mount a comeback.

They were inches away from doing just that.

Cody Ransom's homer capped a four-run burst in the eighth inning and the Milwaukee Brewers, after firing their bullpen coach, held off Houston 8-7 Monday night.

"We had a lot of close plays today, and if one or two of them go our way, it could be a completely different game," Houston's J.D. Martinez said.

The Brewers dismissed bullpen coach Stan Kyles before the game, then watched their relievers barely hang on to the victory.

Milwaukee scored four times in the seventh for a 4-3 lead, but the Astros tied it in the eighth against Livan Hernandez. Ransom's three-run shot gave the Brewers an 8-4 lead in the bottom half before Houston rallied for three runs in the ninth against Hernandez, Kameron Loe and John Axford.

Axford got Martinez to ground out with runners at the corners for his 17th save in 24 chances.

"Tip your hat. The guy made an amazing play on it," Martinez said of the final play, a gem by shortstop Cesar Izturis. "It was bang-bang. We looked at it, and he might have beaten me by a hair. The ball was rolling up to the tip of his glove."

Ryan Braun, who leads the NL with 28 home runs, sat out because of blisters on his left hand.

Houston starter Bud Norris allowed three runs and four hits in six innings, but remained without a win in his last 10 starts.

"Bud did a good job," Houston manager Brad Mills said. "We wanted to try to get him through that seventh inning, but walking that leadoff hitter hurt him. He pitched really well. He threw the ball really well."

Hernandez (4-1) gave up the lead in the top of eighth when Jose Altuve led off the inning with a single and scored on Steve Pearce's double to tie it at four.

Milwaukee responded in its half.

Jonathan Lucroy led off with a hustle double off Francisco Cordero (1-3), lining the ball into left field and barely beating the throw into second with a head-first slide. Nyjer Morgan, attempting to bunt Lucroy over, reached when reliever Xavier Cedeno threw late to third. Lucroy scored when Izturis hit a dribbler in front of home plate that Cedeno couldn't pick up. Ransom followed with a 423-foot home run above the Brewers' bullpen in left.

Things got interesting again in the Houston ninth.

"Once we got a couple guys on, everybody got confident, and everybody was in the moment," Martinez said. "Tying run on base, winning run on base, it just didn't work out today."

With one out, Jordan Schafer walked and went to second on defensive indifference, scoring on Brian Bogusevic's single off Kameron Loe. Altuve walked and scored on Justin Maxwell's double.

Axford then came on, and Pearce hit a sacrifice fly to the warning track in right to score Altuve. Axford then hit Brett Wallace with a pitch. Martinez lined a ball to the hole between short and third. Izturis dove to make the play and fired a one-hopper to first to get Martinez, as Corey Hart held on to the ball with a snowcone catch -- just another harrowing finish for the Brewers' bullpen.

"I have not looked at it," said Mills, who argued the call afterward. "I thought he was safe, from where I'm at. The umpire has got to make the call right now, in his real time."

Milwaukee starter Marco Estrada, whose last win came on Aug. 23, 2011, allowed six hits and three runs, two earned, in seven innings, striking out six and walking one. The Astros scored runs on sacrifice flies by Pearce in the first and Altuve in the third, and Scott Moore added a solo homer in the seventh, his fifth and third against the Brewers.

"We were swinging tonight," Pearce said. "We had some big hits, and we battled in the ninth inning. We kept on hitting. We didn't give up. Even though we didn't get the win, we battled out butts off."

Norris and the Astros, however, saw the lead slip away.

"I felt good," Norris said. "I thought I was getting there to the pitch count. I knew my spot was coming up. It happens. I wanted to keep going out there and keep putting up zeroes. But, unfortunately, that last inning didn't go very well."

Houston had lost a franchise-worst 12 in a row before beating the Pittsburgh Pirates, 9-5, on Sunday -- the same day they announced they had traded third baseman Chris Johnson to the Arizona Diamondbacks for two prospects.

Said Mills, "Things right now, it seems like it's not clicking to go our way."

NOTES: Pearce made a great play in the sixth, leaping into the right-field wall and a cage-covered window to catch a fly ball from Hart. ... Lucroy took to Twitter to react to Kyles' dismissal. "We are all to blame, not just one guy," Lucroy tweeted before the game. "Win as a team, lose as a team. Tough times don't last, tough people do. Let's get after it tonight." ... The Astros recalled Brett Wallace from Triple-A Oklahoma City before the game, and he started at first base. To make room for Wallace, the club optioned utility man Brian Bixler to Oklahoma City. ... Brewers CF Carlos Gomez was chosen NL co-Player of the Week. Gomez hit .346 with four home runs, 10 RBIs, 10 runs and three stolen bases in seven games last week.