PHILADELPHIA — Giancarlo Stanton launched his major league-leading 47th home run. And to Miami Marlins Manager Don Mattingly, it may have been his most impressive home run yet.

“That one today was extremely long,” Mattingly said. “That was into the wind. If that wind’s not blowing in, that things up on the, it might have hit the Holiday Inn back there.”

Stanton blasted that towering shot to center field, J.T. Realmuto hit an inside-the-park homer and the Marlins overcame a five-run deficit to beat the Philadelphia Phillies 9-8 on Thursday.

Stanton led off the third inning with the homer, his 14th in August, extending his club record for most in one month. He now has seven home runs against the Phillies this season, his most against any one team.

Realmuto tied it at 8 in the sixth inning with a two-run shot, which ricocheted off the wall in left-center and past center fielder Nick Williams.

Realmuto put the Marlins ahead in the eighth with a sacrifice fly off Luis Garcia (1-4). Williams made a sliding grab to rob Realmuto of a hit.

“If that ball gets by, that might have been another one right there,” Mattingly said. “J.T., that (home run) was huge for us to get back to even.”

A.J. Ellis and Christian Yelich also homered for Miami. Rookie Rhys Hoskins and Tommy Joseph homered early as Philadelphia took an 8-3 lead.

Jarlin Garcia (1-2) won in relief and Brad Ziegler picked up his eighth save.

It was Garcia’s first career win. When Realmuto put the Marlins ahead, Garcia was unable to contain his joy.

“I got excited because I knew I was in line to get the win,” he said through a translator. “I actually let out a yell in excitement.”

The Marlins moved back to .500 at 63-63 after winning three times in the four-game series. The Phillies dropped to 46-80, the worst record in baseball.

DODGERS 5, PIRATES 2: Yasmani Grandal and Adrian Gonzalez hit back-to-back home runs in the eighth and Los Angeles pulled away at Pittsburgh to post its 90th win of the season.

Grandal’s 18th of the year gave the Dodgers a two-run lead. Gonzalez pushed it to three moments later with a shot to nearly the same spot in the right-field seats.

REDS 4, CUBS 2: Jose Peraza hit a pinch bases-loaded double in the eighth to rallying host Cincinnati to a win over Chicago that averted a series sweep.

The comeback ended the Cubs’ five-game winning streak, one shy of their season high.

PADRES 4, CARDINALS 3: Carlos Asuaje’s RBI single in the ninth gave San Diego the lead and Jose Pirela’s sacrifice fly proved to be the winner as the Padres rallied at St. Louis.

DIAMONDBACKS 3, METS 2: Robbie Ray returned to a big league mound for the first time since being hit in the head with a line drive last month, striking out nine in five innings as Arizona won at New York. Ray (10-5) allowed one run and two hits.

AMERICAN LEAGUE

RAYS 2, BLUE JAYS 0: Alex Cobb and four relievers combined on a six-hitter and center fielder Kevin Kiermaier made two spectacular catches to help Tampa Bay top visiting Toronto.

WHITE SOX 5, TWINS 1: Derek Holland pitched six effective innings, Yolmer Sanchez homered and Chicago won at home.

INTERLEAGUE

ROCKIES 3, ROYALS 2: Pat Valaika hit a two-run homer with two out in the eighth and Greg Holland finished for his 36th save in Colorado’s road victory.