PHILADELPHIA (AP) The Cardinals were glad they pulled this one out, eventually.
Matt Carpenter hit a sacrifice fly in the 12th inning, lifting St. Louis over the Philadelphia Phillies 6-5 on Saturday night.
Jhonny Peralta homered for the Cardinals, who have won eight of 10 and closed within a half-game of NL Central-leading Milwaukee.
''It would have been a tough one to lose,'' St. Louis manager Mike Matheny said. ''It was one of those tough ones to swallow. But the guys fought hard and kept coming.''
Ryan Howard homered and Marlon Byrd and Carlos Ruiz each drove in a pair of runs for the Phillies.
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.
Seth Maness (5-2) pitched two scoreless innings and Trevor Rosenthal earned his 38th save in 43 chances.
''The bullpen did a nice job holding us where we were after it got tied up,'' Matheny said.
The teams combined to use 14 pitchers in a game that took 4 hours, 53 minutes.
The Phillies tied it at 5 in the eighth on Byrd's two-run single off Pat Neshek, who relieved Randy Choate after the bases were loaded with no outs.
Cardinals starter Shelby Miller was in line for the win after going six innings and allowing three runs and five hits.
''Overall I felt strong,'' Miller said. ''I thought I did a good job getting ahead of the hitters.''
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.
''Not a good defensive inning for us,'' Phillies manager Ryne Sandberg said.
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.
''Once the ball was caught I think he was focused on the ball and was not aware of where the baserunners were,'' Sandberg said.
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.
Buchanan was upset he was lifted so soon.
''That caught me off-guard, honestly,'' he said. ''I didn't expect that. I wasn't too happy about it. But I can't control that.''
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.
Kolten Wong's drive to center leading off the ninth went over the head of Ben Revere in center, bounced off the ground where it meets the wall and then ricocheted off Revere's foot over the wall. Wong was awarded second base and stayed there after crew chief Brian O'Nora reviewed the play for a rules check for a deflected ball being a double.
PHILLIES OWNER DIES
Sally Buck, one of the Phillies' owners, died on Saturday, the team said. She was 83. Buck and her late husband, Alexander, became owners in 1981.
With his 18th homer, Peralta extended his club record for homers in a season by a shortstop.