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.
The Phillies are the first team in the modern era to win by at least six after trailing by at least six twice in the same season, according to STATS. The other was last week, when they rallied from down 7-0 in the fourth inning to defeat the Chicago Cubs 17-8 on Sept. 16.
"Well, hopefully we just keep the momentum going," Phillies manager Joe Girardi said.
The club finishes its 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 Pittsburgh take a 6-0 lead.
"Just the grit from the guys," Nola said of the key to the comeback. "They were confident they were going to score runs. You could feel it. It's pretty cool."
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.
"I was ready for the situation," Torreyes said via interpreter. "I knew what was at stake and knew what I needed to do. It was very special."
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.
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.
"They picked me up big time," Nola said. "I tried to stay in as best as possible. I just wanted to put up as many zeroes as I could."
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.
"We got kind of passive," Pirates manager Derek Shelton said. "Nola locked it in. This guy has good stuff. We have to continue to push when we get good leads. That's just a sign of youth."
Girardi's plan to rest Realmuto didn't last long. He called on Realmuto in the sixth inning and it paid off in a big way.
"I rested him for five innings," Girardi said. "There's his rest."
Philadelphia also bounced back from a 7-0, third-inning deficit to defeat Washington 11-8 on July 29 and overcame a 6-0, sixth-inning deficit to win 7-6 at the Nationals on Sept. 2.
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.
RHP Kyle Gibson (10-8, 3.51) starts for Philadelphia in the second contest of the four-game series on Friday night.
Ronald Torreyes' 3-run HR grabs the lead for Phillies in comeback win
Ronald Torreyes hits a three-run home run to left field in a 12-6 win for the Phillies at Citizens Bank Park.