All four of Houston's runs and five of its nine hits came with two outs.
"We finally got something going late in the game," said Astros manager Cecil Cooper, who celebrated his two-year anniversary of getting the job with a win. "We had a couple of big swings, all with two outs -- Keppy's swing, and the one by Erstad was definitely big. We've been scuffling to get runs."
The victory was the Astros' fifth win on the road in their past 19 games. But after a pair of disheartening losses to the division-leading Cardinals, the significance of the comeback victory wasn't lost on the players.
"We've got a lot of guys that have played this game a long time, and guys get frustrated," Erstad said. "We'd like to play better and have more wins and all that good stuff. We're professionals, and we're going to continue to come out there and fight to the very end, and that's what we did today."
Jose Valverde (2-2) threw two scoreless innings in relief for the Astros, allowing one hit and one walk for the win. Cooper brought his closer into a tie game to start the eighth to face Albert Pujols, Matt Holliday and Ryan Ludwick, the heart of the St. Louis order.
"He hadn't pitched, and we tried to set him up for two [innings]," Cooper said. "It just came down to that. I was thinking in the sixth and seventh when I had to do that. That's the guy you want in that situation."
The Astros sent eight batters to the plate in the second against St. Louis starter Chris Carpenter and scored a pair of runs. Kazuo Matsui had an RBI double, and Michael Bourn beat out an infield hit to score Matsui from third base and make it 2-0.
"You want to get more there," Cooper said. "We would have loved to have gotten more, but he's pretty tough."
Holliday homered in the second to cut the lead to 2-1, but Astros starter Brian Moehler retired 13 of the next 15 batters he faced before running into trouble in the sixth. Julio Lugo doubled with one out, and the Astros intentionally walked Pujols to get to Holliday, who got both runners into scoring position with a groundout.
Ludwick followed and sent Moehler's 0-1 pitch back up the middle for a two-run single that gave the Cardinals the lead, 3-2.
"They've got a good lineup," Moehler said. "The pitch came back over the plate. He hit it back up the middle. You tip your hat to him. It didn't beat us, so that's good. We won the ballgame."
The Astros tied the game at 3 in the eighth when a struggling Miguel Tejada singled with two outs and scored from first base on Erstad's double to right-center. Cardinals Center fielder Colby Rasmus fumbled the ball, but Tejada never stopped running.
"It was a cutter in, and I felt like I got it in," McClellan said. "We had been coming in all day, so he was probably looking in there, but it was just one of those that found a hole. If I could go back and do it again, I don't think it was the wrong pitch, I don't think it was a bad pitch, but he just got a hit. Nothing you can really do about it."
Keppinger, who was hitless in his previous eight bat-bats, socked a 2-2 pitch from McClellan over the left-field wall with two outs in the ninth for what he believes is his first game-winning homer. It was his first homer of any kind since June 19, a span of 115 at-bats.
"We haven't given up," Moehler said. "All you can do is ask to continue to play hard and then you go out there and see what happens. No one's given up by any means. I think we're only three games back from Chicago. There's a lot to be salvaged left in the season. You never know what could happen. We picked up a game today. I know we're still 11 games out, but still, we picked up a game."