Jhonny Peralta homered for the Cardinals, who have won eight of 10 and closed within a half-game of NL Central-leading Milwaukee.
Pinch-hitter Daniel Descalso drew a leadoff walk in the 12th from Ken Giles (2-1). Descalso went to second on Jon Jay's sacrifice bunt and moved to third on Peter Bourjos' infield single. Carpenter then flied out to deep left.
The teams combined to use 14 pitchers in a game that took 4 hours, 53 minutes.
Cardinals starter Shelby Miller was in line for the win after going six innings and allowing three runs and five hits.
A pair of Phillies errors helped the Cardinals break a 2-all tie and go in front in the sixth with three runs off reliever Mario Hollands.
After A.J. Pierzynski led off with a double, Oscar Taveras hit a sinking liner to left. Domonic Brown appeared to pull up on a catchable ball and Pierzynski took off for third when Brown hesitated to throw back to the infield. Brown then threw the ball away, allowing Pierzynski to score.
David Buchanan got his first no-decision in his 14th start, giving up two runs and eight hits in five innings. The right-hander is filling in for Cliff Lee, who is out for the season with an elbow injury.
Cardinals: RHP Jason Motte missed his 20th game with a lower back strain. The reliever is 0-0 with a 4.91 ERA in 24 games.
Phillies: RHP Mike Adams will begin a rehab assignment on Tuesday at Triple-A Lehigh Valley. A shoulder injury has sidelined him since June 7. He is 2-1 with a 2.12 ERA in 19 games.
Cardinals: RHP Justin Masterson makes his fifth start for St. Louis since being traded from Cleveland. Masterson is 1-0 with a 2.16 ERA in three games against Philadelphia.
Phillies: RHP Jerome Williams looks to continue his strong performance since being claimed off waivers from Texas. He is 1-0 with a 2.19 ERA in two starts with the Phillies.
Link to box score: St. Louis (70-57) 6 at Philadelphia (57-72) 5 (12 innings)
Join the pre-game, in-game and post-game discussion about each contest at The Cardinal Nation message board.