Pujols, who had to be restrained from going after Villanueva, doubled to start a four-run eighth-inning rally and said, "I congratulate (Villanueva) for doing that."
The victory kept hope alive in St. Louis. The Cardinals trail the Brewers by only 3 1/2 games in the wild-card race, although the teams don't play anymore this season.
Cardinals manager Tony La Russa, again praising his team's effort, said, "We've got more talent than people think."
Right-hander Chris Perez gained his sixth save since being installed as the closer, fanning three hitters in the ninth.
Himself a closer in the 2006 postseason, Cardinals righty Adam Wainwright, who started Wednesday, said, "(Perez) was awesome. I think that's what he's made for -- to be in the ninth inning right there."
CARDINALS 5, BREWERS 3: After losing seven straight times to the Brewers, the Cardinals won the last meeting of the season between the teams. RF Ryan Ludwick hit his 32nd homer and drove in another run with a double in the eighth inning.
NOTES AND QUOTES:
--LF Rick Ankiel, bothered for a month with a strained abdominal muscle, didn't start against LHP Manny Parra. Ankiel, 4 for his last 36, said the injury still affects him while running but not while hitting.
Ankiel visited a specialist Wednesday and said he was told, "'You're probably going to deal with ups and downs the rest of the season.' It's not getting worse, but it feels like it's kind of plateaued, where it's not getting better."
--1B Josh Phelps, who hit 31 homers at Class AAA Memphis, had his contract purchased from that club to be a pinch hitter down the stretch. He singled in his first pinch-hitting assignment Wednesday.
--LHP Jaime Garcia, who was hit hard in a couple of recent outings, including Tuesday, was optioned to Class AAA Memphis and may not be recalled in September.
--In his latest step toward rejoining the rotation, RHP Chris Carpenter, recovering from a shoulder strain, threw some 60 pitches in a bullpen session Wednesday. "A little more effort, a few more pitches," he said. "It felt good. I definitely put a lot more effort it." Carpenter was unclear what comes next, but asked if he would pitch before the end of the season, he said, "I would hope so."
--The Cardinals reached 14 games over .500 for the fifth time this season.
--C Yadier Molina extended his hitting streak to seven games with two hits. He is 13-for-28 (.464) in that run and is hitting .329 in August.