Ron Villone got two outs in the seventh, Kyle McClellan pitched a perfect eighth and Ryan Franklin finished for his 12th save in 16 chances.
Cole Hamels (9-6) was the hard-luck loser for struggling Philadelphia, which maintained a slim lead in the NL East.
The Phillies have lost nine of 11 at home. They have dropped four of five since completing their second three-game sweep of Atlanta on the road within a month. They went 5-13 after sweeping the Braves June 6-8.
Ankiel drove an opposite-field shot to left-center for his 19th homer to give the Cardinals a 1-0 lead in the fifth.
Ludwick ripped an 0-2 pitch deep to left-center for his 18th homer in the sixth.
Hamels gave up one other hit in seven innings, striking out eight. He lost 1-0 to Washington in the second game of the season.
Phillies right fielder Jayson Werth threw out Chris Duncan trying to score on a fly ball to end the top of the eighth and keep the deficit at 2-0. Duncan barreled into catcher Chris Coste, who got up after staying down a few seconds.
Earlier this season, Cardinals catcher Yadier Molina sustained a mild concussion after a collision with Philadelphia's Eric Bruntlett.
Pineiro escaped trouble in the second after Pat Burrell's double put runners on second and third with no outs. Werth struck out and Carlos Ruiz grounded into a double play after a walk had loaded the bases.
Pineiro left after Pedro Feliz singled to put two runners on in the seventh. But Villone got Coste, a pinch-hitter, to ground into a double play to end the threat.
Notes: Werth's fourth-inning single extended his hitting streak to a career-best 10 games. Phillies 1B Ryan Howard singled in the ninth for an 11-game hitting streak. ... Molina's 13-game hitting streak was snapped. ... The Phillies are 23-22 at home, 25-21 on the road. ... LHP Mark Mulder makes his first start Wednesday since last Sept. 16. He's returning from two shoulder surgeries. Mulder has made two relief appearances for St. Louis since returning two weeks ago. ... The Phillies have been shut out six times.