MILWAUKEE -- Cecil Cooper looked away in disgust, thinking Brewers slugger Prince Fielder had just hit a game-tying, ninth-inning homer to drive a knife into the Astros' hearts. Closer Jose Valverde thought the ball was gone, too, and was beginning to lament a blown save.

It wasn't until a leaping Hunter Pence came down with the ball at the right-field wall did Cooper, Valverde and the rest of the Astros breath easy.

Pence hit a two-run home run in the eighth inning that gave the Astros the lead, and Valverde retired Fielder to strand runners at second and third and seal Houston's dramatic 8-5 win over the Brewers on Sunday at Miller Park.

"I thought the stinkin' ball was out of the ballpark," Cooper, the Astros' manager, said. "I turned to walk down to sit down. I thought it was a tie ballgame."

Fielder, who hit a 457-foot homer off Roy Oswalt in the sixth, stepped to the plate in the ninth representing the tying run. Cooper paid a visit to the mound, but he didn't consider walking Fielder, and instead told Valverde to pitch him away.

Valverde executed the proper pitch, and Fielder nearly drove it over the right-field wall. Pence was playing deep to prevent a double and caught the ball in the air just before he hit the wall.

"This guy is hitting good," said Valverde, who got his 16th save. "I thought it was a home run, but once Pence catches it, I was saying, 'Thank you.'"

The win certainly served as a boost for the struggling Astros, who snapped a three-game losing streak, avoided getting swept by the Brewers and finished their seven-game road trip to Florida and Milwaukee at 2-5.

"This was a good win for us," Cooper said. "We've had a few at home where we tied the score and came back in the ninth or had some walk-offs, but never like this. This was pretty dramatic. A couple of big, big swings were the difference in the game."

The Astros came from behind twice, thanks to homers by Geoff Blum and Pence. Blum hit a three-run homer in the sixth that put Houston ahead, 4-2, but the Brewers answered with three runs off Oswalt in the bottom of the inning, including Fielder's mammoth homer, to take a 5-4 lead.

Houston scored three runs in the eighth against reliever David Weathers, taking the lead for good when Pence hit a two-run homer to right that made it 6-5. Jason Michaels added an RBI single in the eighth, and Blum had an RBI single in the ninth to make it 8-5.

"They both were big," Cooper said of the homers by Pence and Blum. "I can't minimize what Blum's home run did, and you definitely can't take away Hunter's. That was pretty dramatic. It was a 3-2 pith from one of the better setup guys, and he went to the opposite way. That shows me he had a great plan and stayed with it."

Pence had a home run changed to a foul ball in his previous at-bat in the sixth inning. Umpires reviewed replays and determined correctly that it curved in front of the left-field foul pole. He wound up flying out to right field.

Jeff Fulchino (5-4) got the win in relief by working two-thirds of an inning in the seventh. He hit Braun with a pitch with one out before striking out Fielder swinging and getting Mike Cameron to fly out.

"You don't want to put anybody on base before you face Prince," Fulchino said. "But the split got away from me. I wanted to make sure I really made my pitches against Prince. I was able to make a good split to start him off with and work fastballs away and get a big punchout."

Oswalt, making his second start since missing two weeks with a strained left lower back, allowed eight hits and five runs and struck out five batters in six innings, becoming the first Astros starting pitcher in a week to pitch into the sixth frame.

He gave up a two-run homer to Braun in the first, before settling in to retire 13 of the next 17 batters he faced. Oswalt picked up his career-high 14th no-decision of the season.

"This is the first time since the back injury I felt pretty decent," Oswalt said. "In Florida, I was kind of hesitant of throwing too hard. Today I gave up two runs in the first and said it's either going to be a blowout in the next two or three batters or I'm going to last. I started going harder and actually made it through it pretty well."

Blum's blast in the sixth put Oswalt in position for a win, but Braun singled to start the sixth and Fielder crushed a 2-2 pitch and bounced it off the scoreboard in straightaway center to tie the game. The Brewers pushed across the go-ahead run on a fielder's choice later in the inning.

But Oswalt left the ballpark happy.

"The boys kept fighting," he said.