PITTSBURGH -- What looked like an easy night after two innings turned into a struggle for the Houston Astros.
Lance Berkman hit a three-run homer in a four-run first inning and Mike Lamb hit a three-run homer in a four-run second as the Astros built an 8-0 lead and then held off the last-place Pittsburgh Pirates 12-8 on Wednesday night.
"These guys are unbelievable. They fight you right down to the end," said Berkman, who had five RBI, including his 20th homer. "They've played us real tough this year. Every time we come in here I say, 'How in the world are these guys in last place?"'
It was the seventh win in eight games for Houston, which remained two games in front of Philadelphia in the NL wild-card race. The Phillies beat Atlanta 10-6 in 10 innings.
Roy Oswalt (18-12) allowed four runs, three earned, and nine hits over six innings to win for the fourth time in five decisions. He struck out six and walked two as Houston moved 14 games over .500 (83-69) for the first time this season.
"They're not playing for anything, but they still give 100 percent," Oswalt said. "They battled. These guys just play one at-bat at a time. I think they're going to have a good team in the coming years.
"The important thing is you can't let an 8-0 lead go to waste. The biggest thing is us getting the win. It doesn't matter how we got it."
Pittsburgh cut the lead to 8-4, but the Astros scored two runs off reliever Brian Meadows. The Pirates got within 10-7 on Ryan Doumit's two-run homer off Russ Springer in the seventh and Freddy Sanchez's solo homer off Dan Wheeler in the eighth.
Houston scored two unearned runs in the ninth when Lamb doubled, moved to third on Jason Lane's single and scored when Doumit mishandled third basemen Ty Wigginton's throw home on Brad Ausmus' grounder. Lane moved to third on the error and scored on pinch-hitter Jose Vizcaino's groundout.
Brad Eldred added a solo homer in the ninth for the Pirates.
Kip Wells (7-17) became the first pitcher in the majors to lose 17 games this season. He lasted two innings, his shortest outing since retiring just two batters on Aug. 24 against St. Louis, allowing eight runs and five hits while walking three.
"I give these guys in this clubhouse credit for not just laying down, because even though I was out of the game and frustrated and upset about what happened, these guys still had to go out there and play and give them a fight," Wells said.
Said Pittsburgh interim manager Pete Mackanin: "Kip was disappointing once again. I don't know how to fix him. We have to get him on track, and there's not much time left.
"You can talk about how we battled back, but that's not me. It's win or lose. You win with good pitching, good defense and clutch hitting. We made too many errors."
Berkman drove in a run with a sacrifice fly in the second inning and followed Morgan Ensberg's two-out double with an RBI single in the sixth. Lane added a solo homer for Houston in the seventh.
"It was nice for us to keep the offense going, keep tacking on runs through the ninth," Lane said. "It was nice to see because a lot of guys chipped in."
Sanchez doubled, moved to third on Jack Wilson's sacrifice and scored on Jason Bay's double in the third inning.
In a two-run fourth, Nate McLouth walked, moved to second on Sanchez's two-out single and scored on Wilson's single. Bay then hit a grounder to third baseman Ensberg, who threw wildly past second baseman Chris Burke and into right field for an error, allowing Sanchez to score.
Craig Wilson led off the Pittsburgh fifth with a triple and scored on Doumit's groundout.
"I thought we had plenty of runs, we had Roy on the mound and things looked pretty good," Houston manager Phil Garner said. "Then a few innings later things didn't look so good. It was a game you didn't want to let get away."
Lamb's homer to right, his 10th, gave the Astros an 8-0 lead and followed Berkman's sacrifice fly. Houston had loaded the bases on Willy Taveras' one-out single and walks to Craig Biggio and Ensberg.
Taveras led off the game with a single and scored when third baseman Rob Mackowiak committed a throwing error on Biggio's grounder. After a walk to Ensberg, Berkman homered to left for a 4-0 lead.
Berkman became the third player in Astros history to have six consecutive 20-homer seasons, following Glenn Davis and Jeff Bagwell. Houston is 16-3 this season when Berkman homers. ... Taveras has 161 hits, most by a Houston rookie since Bagwell had 163 in 1991. ... Bay's 14-game hitting streak is the longest by a Pittsburgh player this season. ... Houston is 6-1 in its last seven games at PNC Park.