Joe Girardi didn’t go with the every-game-is-important line beforehand. Not with the division-leading Red Sox in town.

“They definitely are bigger,” he said Friday afternoon of the upcoming three games. “We need to make up ground.”

The Yankees did Friday night in dramatic fashion, rallying from three runs down in the eighth inning to knock off the Red Sox, 5-4, in front of perhaps the loudest Stadium crowd of the season, a sellout of 46,509.

“It was electric, man,” said Todd Frazier, whose RBI single in the eighth snapped a 3-3 tie. “That crowd was electric.”

The wild victory was jeopardized when Aroldis Chapman walked the bases loaded to start the ninth, but a terrific defensive play by leftfielder Aaron Hicks — whose two-run homer had jump-started the five-run eighth — short-circuited a Boston rally.

Eduardo Nunez of the Red Sox is tagged out trying to tag up in the ninth inning by Todd Frazier of the Yankees at Yankee Stadium on Friday, Aug. 11, 2017. Photo Credit: Jim McIsaac

“He’s a game-changer,” Brett Gardner said of Hicks, who missed nearly six weeks with an oblique strain before returning from the disabled list Thursday. “We’re glad to have him back.”

advertisement | advertise on newsday

The win brought the Yankees (61-53) within 3 ½ games of the Red Sox (65-50), whose winning streak was snapped at eight.

It was a theatrical start to a stretch of 10 games between the rivals in a 24-day span. “Very important,” Hicks said. “We need to get as many wins as we can against these guys. Just shows we’re willing to fight back, and that was also very important.”

Coming in, the Yankees had scored two or fewer runs six times in their previous eight games, and they remained on that familiar road of futility for seven innings. But after Eduardo Rodriguez fired six shutout innings and Matt Barnes pitched a scoreless seventh, they hammered former Met Addison Reed.

Hicks’ two-run homer to right made it 3-2 and ended the Yankees’ shutout streak at 16 innings over the last two games. “That was huge,” Frazier said. “We grind. Everybody came through at the end. Hicks started us and the wheels just keep on turning.”

Gary Sanchez singled and went to second on a wild pitch before Aaron Judge walked. In came Joe Kelly to face Didi Gregorius, who entered the night with 12 hits in his last 25 at-bats but was 0-for-3 to that point Friday night. Gregorius lined an RBI single to left to tie it at 3, Frazier’s single made it 4-3 and Ronald Torreyes’ sacrifice fly to left produced a 5-3 lead.

Yankees videos

Chapman walked Jackie Bradley Jr., Eduardo Nuñez and Mookie Betts to begin the ninth, and Andrew Benintendi then sent a sacrifice fly to left. Hicks made the catch just in front of the warning track and fired a strike to Frazier, who made a nice pick of the one-hop throw and tagged Nuñez for the second out. Mitch Moreland flied to center to end it. “Definitely a big play,” Chapman said through his translator. “A play that saved the game.”

Girardi chalked up Chapman’s control issues to “rustiness,” given that the closer, who picked up his 15th save, hadn’t pitched since last Saturday. “You can’t really use that as an excuse,” Chapman said. “Just a bad day.”

Jaime Garcia, making his second appearance with the Yankees, allowed three runs and seven hits in 5 2⁄3 innings. Adam Warren chipped in 2 1⁄3 scoreless innings, allowing one hit and giving his club a chance to come back. His effort, Girardi said, was “as significant as anything else that happened tonight.”

Said Warren: “I just felt like our offense was going to come through at some point and you wanted to keep the deficit at three and give them a chance. We just knew they were going to come through and they came through big for us.”