PHILADELPHIA (AP) — J.T. Realmuto homered and drove in four, Ronald Torreyes hit a go-ahead, three-run home run in the sixth inning and the Philadelphia Phillies erased a six-run deficit to beat the Pittsburgh Pirates 12-6 Thursday night and pick up ground in the NL East.

Didi Gregorius also homered for the Phillies, who have won three straight and seven of nine to get within two games of first-place Atlanta with nine games left. It’s the fourth time this season and third time this month Philadelphia won after trailing by at least six runs.

READ MORE: SEPTA Union Unanimously Approves Strike If Deal Isn't Reached

The Phillies finish their home schedule with three more against the 95-loss Pirates before ending the regular season with six on the road, beginning Tuesday with the first of a three-game set in Atlanta.

Ke’Bryan Hayes and Colin Moran homered for the Pirates on a cool, rainy night.

Aaron Nola (9-8) bounced back from a shaky start that saw the Pirates take a 6-0 lead.

The Phillies went ahead in the sixth. Realmuto, who was held out of the starting lineup to rest, led off with a pinch-hit single. After two groundouts, the Pirates intentionally walked pinch-hitter Matt Vierling. Torreyes, pinch-hitting for Nola, followed and lined a 2-0 fastball from Anthony Banda (2-2) over the wall in left to put the Phillies up 8-6.

Realmuto’s two-run homer in the seventh made it a four-run advantage, and he lined a bases-loaded, two-run single to center in the eighth.

Philadelphia started the comeback with five runs in the third that began with Gregorius’ leadoff homer to deep right. Jean Segura’s sacrifice fly, Andrew McCutchen’s double and Brad Miller’s single also plated runs in the frame.

The Pirates scored five runs in the second. Starter Connor Overton, in his first career at-bat, blooped a bases-loaded, two-run single that fell in between third baseman Freddy Galvis and left fielder McCutchen. Hayes followed with a three-run homer to right to make it 5-0. It was 6-0 Pittsburgh when Moran led off the third with a long drive to right.

READ MORE: Philadelphia Energy Solutions Refinery Rebranded As The Bellwether District

Nola settled down from that point, retiring his final 12 batters. He allowed six runs on six hits with eight strikeouts and a walk in six innings.

Archie Bradley pitched a 1-2-3 seventh and José Alvarado got the first out in the eighth to make it 15 straight Pirates retired before Alvarado walked Bryan Reynolds.

THE FIGHTINS

Philadelphia bounced back from a 7-0, third-inning deficit to defeat Washington 11-8 on July 29, overcame a 6-0, sixth-inning deficit to win 7-6 at the Nationals on Sept. 2 and rallied from down 7-0 in the fourth inning to defeat the Chicago Cubs 17-8 on Sept. 16.

TRAINER’S ROOM

Phillies: LHP Matt Moore (lower back strain) was placed on the 10-day IL retroactive to Sept. 20. LHP Christopher Sánchez was recalled from Triple-A Lehigh Valley to replace him.

UP NEXT

MORE NEWS: Philadelphia Weather: Chance Of Severe Weather As Parts Of Region Could See Up To 3 Inches Of Rain

RHP Kyle Gibson (10-8, 3.51) starts for Philadelphia in the second contest of the four-game series on Friday night.