The reversal of fortunes happened after Matt Holliday was called for interference at second base on what appeared to be the game-ending play for the Cardinals in the bottom of the ninth.
Skip Schumaker crossed home plate after Ryan Ludwick appeared to beat out a double play -- with the bases full, one out and the game tied at 3 -- when the relay throw by Cubs shortstop Ryan Theriot pulled first baseman Derrek Lee off the base at first, but as fireworks went off and the Cardinals began to celebrate on the field, second-base umpire Marty Foster ruled that Holliday had illegally slid into second base to cause the errant throw by Theriot. Ludwick was called out at first for the third out of the inning, and the game went into extras.
Rookie Mitchell Boggs then gave up a two-run homer to Jake Fox in the 11th inning as the Cubs hung on to win a bizarre season finale between the two rivals.
"Guys are coming out of the dugout and shaking hands and you think the game's over," Boggs said. "But that's baseball. You have to adapt to the way things change. If I could have gotten us back into the dugout that inning, we would have won the game.
"I made a bad pitch, and he jumped on it. It was a fastball up and in, and to a guy like that with his swing, that's exactly what he was looking for. I was trying to go down and away but I just didn't make the pitch. Poor execution and you tip your hat to him."
Instead of sweeping the Cubs out of town with three consecutive walk-off wins -- which the Cardinals hadn't done since Sept. 1-3, 2000, when they won three straight against the New York Mets -- they instead boarded a late-night flight to Houston to open a nine-game road trip with their magic number to clinch the NL Central still at four.
"It feels good to win a ballgame," said Cubs manager Lou Piniella. "We've played a lot of close games here in St. Louis and have come out on the losing end."
The Cardinals had tied the game at 3 in the bottom of the eighth on a two-out single by Yadier Molina to set up the dramatic ninth inning. Only needing a sacrifice fly to win the game, Ludwick grounded into the 4-6-3 double play -- aided by the interference call on Holliday -- to swing the momentum to Chicago's dugout and send the game into extra innings.
"It's a position you grow up as a kid wanting to be in," Ludwick said of the chance to be the hero. "It's a lot of fun when you get it done but, obviously, when you don't get the job done, not only is it tough on you but I think it makes it even tougher because you feel like you let the whole team down.
"I didn't see the play. I was getting down the line and was avoiding Derrek's tag, and I missed the base, so I scuffled back to get to the base because I didn't feel him tag me, and I looked over to second and saw where they were calling me out for Matty getting a little too wide on the slide."
Lost in the crazy late-game happenings was another solid starting performance from Adam Wainwright. The righty gave up two earned runs in seven innings and struck out 10, the second double-digit outing of both his season and career, but he was again plagued by poor run support.
Wainwright is 13-5 with three no-decisions in 21 starts since May 31, but has given up two earned runs or fewer in all eight of his winless starts. The righty has lost games by scores of 2-1, 2-0, 3-2 and 1-0 and got a no-decision when he allowed one run in nine innings in a 2-1 Cardinals win on July 1 against San Francisco.
The Cy Young hopeful is 18-8 with a 2.59 ERA with two regular-season starts remaining but should have a much better win-loss record than his stats show.
"He pitched outstanding," said manager Tony La Russa. "He really pitched well."
Mark DeRosa and Albert Pujols gave the Cardinals a brief 2-1 lead in the fifth with back-to-back RBI doubles. Pujols' RBI gave him 1,105 for his career, tying him with Jim Bottomley for third on the Cardinals career list.
The Cubs scored two in the sixth to retake the lead at 3-2 before Molina tied the game in the eighth.
While the Cubs enjoy being mathematically alive for a few more days, the Cardinals will start a three-city road trip on Monday knowing that the question is not if they will clinch, but when?
"It was a hellacious effort but we came up a little short," La Russa said. "Wainwright was outstanding again. It's a tough loss but we played to the end, as hard as we could, as good as we could. You turn the page."
B.J. Rains is an associate reporter for MLB.com. This story was not subject to the approval of Major League Baseball or its clubs.