Lance Berkman hit a two-out single and scored on Allen Craig's tying double. Craig entered the game in the third inning when Matt Holliday departed with discomfort in his right hand.
Yadier Molina walked before pinch-hitter Theriot delivered his clutch triple to make it 8-6.
Nick Punto, who had four hits, doubled in Theriot in the seventh and had a solo homer in the ninth. Craig padded the lead with a three-run homer to the Crawford Boxes in leftfield in the eighth.
Eduardo Sanchez (3-1) struck out two in 1 1/3 innings for the win in a game that included seven Cardinals relievers following an early exit by Jake Westbrook.
Skip Schumaker drove in three runs in the fourth, and Berkman had three hits and scored three times. The crowd booed loudly when Berkman, the longtime Astros star, scored the tying run in the seventh.
In other games *
At Milwaukee, Prince Fielder homered three times in a game for the first time in his career, including a two-run shot in the seventh inning that lifted the Brewers to a 6-4 victory over the Pittsburgh Pirates.
* At Miami, Bryan Petersen hit a walkoff home run with two outs and Javier Vazquez (13-11) pitched a five-hitter as the Florida Marlins beat the Washington Nationals, 3-2.
The 35-year-old Vazquez (13-11) may have pitched the final game of his career as he said he is likely to retire at the end of the season.
Before the game, former Chicago White Sox manager Ozzie Guillen tweeted that he was in Miami and "ready to go."
On Monday, it was reported that Guillen had been traded to the Marlins for two minor league players. The Marlins had yet to confirm a deal.
In other news, Marlins second baseman Omar Infante said he had agreed to terms on an $8 million, 2-year contract. He would have been eligible for free agency after the season.
* At New York, Jose Reyes hit two solo home runs but the Cincinnati Reds beat the New York Mets, 5-4, on Drew Stubbs' squeeze bunt in the 13th inning.
The New York Mets have exercised manager Terry Collins' contract option for 2013. General manager Sandy Alderson announced the move even though the Mets are finishing up their third straight losing season. Collins signed a 2-year deal after a wholesale revamping of the Mets' front office following the 2010 season.
* Colorado announced that its entire coaching staff will be back in 2012. Most of manager Jim Tracy's staff had been shrouded in uncertainty before the announcement, most notably pitching coach Bob Apodaca and hitting instructor Carney Lansford, whose old-school style didn't sit well initially with the players this season.