PHILADELPHIA -- Joel Pineiro snapped a long winless drought by making a key pitch every time he needed one.
Pineiro (3-4) allowed five hits and walked three in 6 1/3 innings for his first win since April 29. The right-hander was 0-2 with seven no-decisions in his previous nine starts. He allowed three runs or fewer five times in that span, but couldn't get a win.
"He made pitch after pitch after pitch," Cardinals manager Tony La Russa said. "He used everything he had and didn't make a lot of mistakes. We haven't scored for him most of the time."
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.
"It's frustrating because Cole threw well," Phillies slugger Ryan Howard said. "He did his job. We have to find ways to manufacture runs."
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.
"I usually have trouble with guys that come on more of an angle," Ankiel said. "That changeup is really tough to hit."
Hamels praised Ankiel's hitting skills.
"The way he hit it was very impressive," Hamels said. "I guess that's why he's a hitter now. It was a good pitch out and away and he absolutely crushed it."
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.
"When he pitches a game like that, we have to win," Phillies manager Charlie Manuel said.
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.
"I had a good sinker," Pineiro said. "It worked perfectly."
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.
"We have to be able to score," Burrell said. "Everyone's frustrated because we're getting pretty good pitching, but we haven't been consistent at the plate."
Werth's fourth-inning single extended his hitting streak to a career-best 10 games. 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.