The Cardinals took a 5-3 lead in the top of the 10th on a two-run double by Randal Grichuk off Arquimedes Caminero (1-1). Pittsburgh, which won in 14 innings on a homer by Andrew McCutchen on Saturday, did it again 24 hours later against St. Louis All-Star closer Trevor Rosenthal (1-2).
Starling Marte brought Pittsburgh within a run with an RBI single in the bottom of the 10th. Francisco Cervelli tied it with a single and Polanco followed two batters later with a looping single to right for his fourth hit of the game.
The Pirates took three of four in the series to pull within 2 1/2 games of the Cardinals for the lead in the NL Central heading to the All-Star break. Rosenthal blew a save for only the second time this season.
McCutchen's career-best, 18-game hitting streak ended but his teammates picked him up and brought the streaking Pirates - who trailed St. Louis by nine games on May 8 - within striking distance with 74 games to go.
A night after the Pirates rallied three times to stun St. Louis, they did it again with a bunch of role players chipping in while McCutchen went 0 for 5.
Pirates reliever Tony Watson came on in the eighth trying to protect a 3-2 lead but struggled. He hit Kolten Wong with a pitch to start the inning, gave up a single to Peralta and loaded the bases when Jordy Mercer couldn't handle a chopper by Jason Heyward. Wong tied it on a fielders' choice by Yadier Molina, though Watson avoided further trouble by striking out Peter Bourjos with the bases loaded.
It stayed tied until the 10th when St. Louis went to work against Caminero. Grichuk delivered the big blow, a double to the gap in right-center. Mark Reynolds was thrown out trying to score on Grichuk's third hit of the game, a play that would prove costly minutes later.
The Pirates seemed to be poised to win in nine after another steady performance by Francisco Liriano at the mound and on the plate.
Liriano began the night a career .051 (2 for 41) hitter against left-handed pitchers, so the Cardinals didn't hesitate to have starter Tim Cooney intentionally walk Polanco with Cervelli on third and two outs in the second. Liriano, initially an outfield prospect while growing up in the Dominican Republic, responded by lacing a single to the corner in right. Cervelli trotted home and Polanco made it all the way around from first to give the Pirates an unlikely 2-1 lead.
Peralta tied it with his homer to left in the third before the bottom of Pittsburgh's lineup struck again in the fourth. Sean Rodriguez doubled with one out and scored on a single to right by Polanco.
Liriano made it hold up through 6 1-3 innings, allowing two runs on five hits, walking four and striking out six. He left with two on and one out in the seventh but relievers Jared Hughes and Antonio Bastardo swiftly wriggled the Pirates out of the jam.
Cardinals: LF Matt Holliday hit some shag balls before Sunday night's game. He will sit out Tuesday's All-Star game to give his injured quadriceps a little more rest but should be ready to play for the first time since June 8 when St. Louis opens the second half on Friday against the New York Mets.
Pirates: 1B Corey Hart had a setback in one of his knees while rehabbing a hip impingement and has been shut down. General manager Neal Huntington said Hart will rejoin the team in Pittsburgh and have the knee re-evaluated. Hart has been out since June 21.
Cardinals: St. Louis will send five players to Tuesday's All-Star game in Cincinnati: pitchers Carlos Martinez, Michael Wacha and Rosenthal, as well as Molina and Peralta before beginning the second half of the season at home on Friday against the New York Mets. Lance Lynn (6-5, 2.90) will get the start. Lynn is 1-3 with a 3.42 ERA in six games against the Mets.
Pirates: Pittsburgh sends Gerrit Cole, whose 13 wins lead the majors, A.J. Burnett and Melancon to Cincinnati, as well as McCutchen. The team begins the second half on Friday at Milwaukee when Charlie Morton (6-2, 4.15 ERA) gets the start. Pittsburgh is 133-152 after the break under manager Clint Hurdle.
Link to box score: Pittsburgh (53-35) 6, St. Louis (56-33) 5 (10 innings)