And Houston still found a way to win a game it hopes will provide an emotional lift as it tries to defend its NL pennant.
"It's one of those games where it's really important to win for our own morale, I guess," Lamb said. "It's tough to lose those games, especially when we're fighting for a playoff spot."
The victory left the third-place Astros 6½ games out in the NL Central, and four back in the wild-card race.
It was a crushing loss for the Diamondbacks, who missed a chance to move into a tie with San Diego atop the NL West.
"That's real tough," Conor Jackson said. "It's a long game. Coming back from a double-dipper yesterday in Chicago and flying back, I think we were a little worn out today, but that's no excuse."
Chad Tracy tied a career high with four hits for Arizona. The Diamondbacks had 16 hits but couldn't overcome 10 walks by their pitchers, which tied a season high. Starter Miguel Batista issued seven walks.
"Maybe the worst I've ever done," Batista said.
The Astros liked their chances with Oswalt, who had owned the Diamondbacks. In his first five career starts against Arizona, he was 5-0 with a 0.95 ERA, the lowest ERA by any active pitcher against an opponent with a minimum of five starts.
In his last start, Oswalt beat the Diamondbacks on July 29, limiting them to one run in eight innings.
Oswalt's mastery vanished quickly Friday night. Every Arizona position player except Eric Byrnes had a hit by the third inning.
Oswalt gave up 12 hits and a walk in six innings, allowing four runs and striking out four. But he pitched well enough to leave with a 5-4 lead in the seventh inning.
"I thought Roy did a super job of battling tonight," Houston manager Phil Garner said. "Early in the game we were wondering, the way they kept throwing hits up there, but he kept us in the ballgame."
Chad Qualls replaced Oswalt to start the seventh inning. Qualls gave up a leadoff single to Jackson before yielding Johnny Estrada's 420-foot home run into the swimming pool beyond the right-center field fence to put the Diamondbacks up 6-5.
Houston tied it in the eighth when Lance Berkman hit a 426-foot shot into the right-field seats off reliever Brandon Lyon.
"We had the lead going into the eighth and we gave it up," manager Bob Melvin said. "Then one strike, one hit, one whatever short at the end."
In the ninth, Lamb hit for pitcher Trever Miller (1-3) with one out and belted reliever Tony Pena's first pitch 418 feet into the right-field seats for his second pinch-hit homer of the season.
"He's a guy who throws hard," Lamb said of Pena, a rookie right-hander. "Swing early and hope you hit it, pretty much. It was a pitch I could handle, and good things happened."
Taveras followed with his first homer of the year, a shot to left off Pena (3-1). It was Taveras' first home run in 739 at-bats.
But the Astros weren't safe. The Astros needed both runs when Lidge struggled.
Lidge entered in the bottom half of the ninth looking for his 25th save but was pulled after he walked Stephen Drew on four pitches to load the bases with two outs. He also surrendered a leadoff single to Jackson and a walk to Orlando Hudson.
Garner bounded out of the dugout and called on Dan Wheeler, typically used as a set-up man.
"I felt like I had to go to Wheeler," Garner said. "I just felt like I had to do it."
Wheeler walked Jeff DaVanon to force in a run then struck out pinch-hitter Carlos Quentin for his third save in five opportunities.
The Astros had their victory, even if it wasn't very pretty.
"I give credit to our ballclub for not quitting and battling right back," Garner said.
- Batista's second-inning wild pitch was his 13th, most in the league.
- Oswalt's second-inning single was his eighth hit, most among Houston pitchers.
- Estrada's homer was the 33rd to land in the swimming pool, and the 15th by a Diamondback.
- 2B Craig Biggio homered for the Astros.
- Drew, who doubled and singled, has four straight two-hit games.