ST. LOUIS -- It was an ugly win, except for one thing. There are no ugly wins in a pennant race in August.

The Cardinals did it the harder-than-hard way, but they did the one thing that mattered on Tuesday night, defeating the Dodgers, 6-4, in 11 innings. Ryan Ludwick jacked a two-run home run to let the St. Louis bullpen off the hook, but it was too late for Chris Carpenter to secure a well-deserved win.

In June, a ninth-inning collapse by Ron Villone and Jason Isringhausen might have been cause for concern. And in some quarters, it still was. But on the fifth day of August, with the Cards one-half game out of a playoff spot and only 47 games left on the schedule, winning wasn't everything -- it was the only thing.

"We have had some heartbreaking losses," said manager Tony La Russa. "If we had lost that one, that would have been up there as high, higher than any of them because of everything that was transpiring and the way that game went. You can just taste that win. Those are the toughest. We'll see the next few days how much it means to us, but it definitely gets us off the first game of the series."

Until the ninth, Carpenter appeared to be well on his way to his first win since Sept. 16, 2006. He pitched five shutout innings on 51 pitches, lifted only because of a rain delay that made the Cards' field staff nervous about his surgically reconstructed elbow. Carpenter departed with a 1-0 lead, and the margin had stretched to four runs by the time Villone entered the game in the ninth.

It was Carpenter's first home start since his Tommy John reconstructive elbow surgery, and it was a big night for the right-hander.

"It's always fun pitching here, and I was looking forward to getting back out on this mound," Carpenter said. "The fans gave me a nice welcome, even when I was walking out to the bullpen to start getting loose. That's always appreciated, and it makes this place special."

For three innings, the Redbirds' relief corps worked seamlessly behind Carpenter. Brad Thompson tossed a perfect sixth, then was removed for a pinch-hitter in the bottom of the inning. Kyle McClellan allowed a hit and a walk over two scoreless innings, getting the game to the ninth, and Albert Pujols' two-run homer in the bottom of the seventh made it a four-run game -- not even a save situation.

But things unraveled quickly in the ninth. Villone allowed a leadoff pinch-hit homer to Andruw Jones, only the third of the year by the former slugger. Isringhausen retired Matt Kemp before allowing singles to Andre Ethier and Russell Martin, and walking Manny Ramirez.

James Loney hit a slow roller that could -- and probably should -- have gone for the second out, but Isringhausen couldn't make the play. Jeff Kent followed with a single that made it 4-3, and Isringhausen was chased. The Dodgers scored the tying run on a sacrifice fly against Ryan Franklin, but Franklin and Jaime Garcia held on through the 11th.

That's when Ludwick delivered his second walk-off home run of the year, giving Garcia his first Major League win and the Cardinals their second win in eight home games. Ludwick has been absolutely scorching the ball, going deep in four straight games.

"I'm just trying to get pitches to hit and drive them," he said. "Tonight, up until that at-bat, I didn't do a real good job. It was nice to see Carp do what he did tonight. He looked great out there. It's always a good sight, seeing him on the bump, doing what he's doing. I'm just glad I could contribute a little bit."

The Cardinals remained 5 1/2 games behind the first-place Cubs in the National League Central, and one-half game behind the Wild Card-leading Brewers.