Polanco's fly ball to left with the bases loaded in the seventh inning scored Carlos Ruiz. Ryan Braun's throw sailed behind a sliding Ruiz and hit the backstop, allowing Valdez to slide home.
Corey Hart hit two solo homers, and Prince Fielder and Alcides Escobar also connected against Halladay (17-10), who pitched seven innings. The right-hander allowed four homers for the first time in 342 career games and 316 starts.
J.C. Romero and Ryan Madson combined to work the eighth before Brad Lidge finished for his 20th save.
Ryan Howard and Jayson Werth hit back-to-back homers for the Phillies.
Halladay appeared in line to lose his third consecutive start before Philadelphia bailed him out with its 11th win this season when trailing after six innings.
Of course, it was a tight one.
The Phillies improved to 38-23 in games decided by two runs or less - the best winning percentage in baseball. In one-run games, they are a sparkling 24-14. Those numbers have them in the hunt for their fourth straight NL East title.
The Phillies scratched together the winning rally against the Brewers' bullpen after a game full of longballs.
Shane Victorino and Carlos Ruiz opened the seventh with singles off Kameron Loe (3-4). Zach Braddock entered and walked Valdez on four straight pitches to load the bases. He got slumping Jimmy Rollins on a fielder's choice that kept the bases full.
Polanco hit a fly ball just a few shades shy of shallow and a strong throw might have nailed Ruiz at the plate. It certainly wouldn't have allowed Valdez to score.
Instead, it's the Phillies who are on a five-game winning streak and the Brewers on a five-game skid.
Halladay, looking to bolster his NL Cy Young Award credentials, was touched for two homers in the second. Fielder hit the first pitch of the inning to right field for his 29th of the season. Escobar lined an 0-2 pitch to left for his fourth.
Halladay left two runners stranded when he struck out Rickie Weeks.
Halladay had allowed only three homers total in his last five starts and 17 this year in 214 innings pitched.
Howard and Werth connected against Dave Bush in the second, tying the game. Howard's 26th homer was a no-doubter to right - Fielder at first never looked up and just pounded his mitt.
Hart went deep in the third and seventh to help Milwaukee take a 4-3 lead. He has 25 on the year.
Chase Utley hit a tying RBI single in the third for the Phillies.
Bush allowed six hits and struck out five in six innings.
NOTES: Halladay has pitched seven innings in nine consecutive starts. ... The Brewers have lost all five games in their losing streak on the road.