PITTSBURGH -- Logan Shafer singled home Nevin Ashley with the go-ahead run in the top of the 13th and the Milwaukee Brewers spoiled A.J. Burnett's return with a 6-4 win over the Pittsburgh Pirates on Thursday night.

Luis Sardinas added an insurance run off Radhames Liz (1-4) with a single as the Brewers beat the Pirates for the seventh straight time despite twice having late leads erased by Pittsburgh home runs.

Andrew McCutchen's 22nd of the season tied it in the eighth. Gregory Polanco's solo shot off Milwaukee closer Francisco Rodriguez tied it again in the 12th after the Brewers had gone up on an RBI single by Ryan Braun.

More from FoxSports

Rodriguez (1-3) got the win after blowing the save. Kyle Lohse earned the second save of his 15-year career.

Burnett gave up three first-inning runs his return from a lengthy stay on the disabled list with a strained right elbow. Pittsburgh remained 4 1/2 games behind St. Louis in the NL Central, but in control of the wild-card race.

Pirates manager Clint Hurdle said he wasn't going to put any sort of limit on Burnett, who was diagnosed with a strained right flexor tendon after laboring through three straight subpar starts following the All-Star break.

The city welcomed the veteran's comeback by projecting green Batman signals -- Burnett's comic book hero of choice -- onto a handful of buildings across the Allegheny River from PNC Park.

The early results were mixed. Burnett hit 91 mph on his first pitch, with Scooter Gennett taking the second and doubling to right-center field. Gennett scored on a groundout by Braun. Adam Lind then hit a sharp single and Khris Davis followed with a long homer off the batter's eye in center to stake Milwaukee to a 3-0 lead.

Burnett, in the final weeks of a 17-year career, recovered quickly. He cruised through his final four innings, giving up only a pair of walks. His three strikeouts gave him 2,487 in his career, moving him past Hall of Famer Don Drysdale and into 32nd on the all-time list.

Milwaukee starter Wily Peralta allowed two runs in six-plus innings and appeared to be in decent position to win for the fourth time in his last five decisions when reliever Will Smith struck out Polanco with the bases loaded to end the seventh to preserve a one-run lead.

McCutchen, however, pulled the Pirates even in the eighth, sending a pitch from Corey Knebel into the first row of seats in right field for his 22nd homer of the season and 150th of his career. McCutchen joined Barry Bonds as the only players in Pirates history to have 150 homers and 150 stolen bases with Pittsburgh.

The Pirates' taxed bullpen -- without setup man Tony Watson and closer Mark Melancon -- finally faltered. Pittsburgh relievers had won 19 consecutive decisions they were involved in dating to June 25, the longest streak in the majors in more than a century.