The 21st annual Subway Series got underway with a bang Monday night in the Bronx. Five of them, to be exact.

Curtis Granderson and Yoenis Cespedes hit the first two, solo shots in the third inning that gave the Mets an early lead.

But it was the final three — a tying home run by Aaron Judge in the sixth, a go-ahead blast by Aaron Hicks in the eighth and an insurance shot by Gary Sanchez later in the eighth — that powered the Yankees to a 4-2 victory before a sellout crowd of 45,619 at Yankee Stadium.

“It’s something that as a team we have,” Hicks said. “We have a deep lineup. I think starting the series off with a win . . . that’s the way you want to start it.”

The Yankees trailed 2-1 when Judge led off the sixth with his 36th home run into the box seats in front of the right-centerfield bleachers off starter Rafael Montero.

Hicks’ go-ahead blast off Hansel Robles (7-4) was a no-doubter deep into the bleachers in right-field and gave the Yankees their first lead. It was Hicks’ 12th homer.

advertisement | advertise on newsday

Sanchez followed three batters later with his 20th, a blast to right-center off Erik Goeddel. It gave the Yankees a two-run cushion to hand to closer-for-a-night Dellin Betances, who notched his seventh save.

The Yankees, who moved to within 4½ games of the AL East-leading Red Sox, were able to shake off Sunday night’s 3-2, 10-inning loss to Boston in which closer Aroldis Chapman allowed the tying home run in the ninth.

While the Yankees chase a playoff spot, the Mets are just trying to finish out the season and make a good showing in the four-game Subway Series. Yankees starter Luis Cessa allowed two runs in 4 1⁄3 innings before leaving with an apparent upper-back injury (he will have an MRI today). Mets starter Rafael Montero, who came in with a 6.06 ERA, allowed two runs and five hits in six innings.

The Mets took a 1-0 lead in the third on Granderson’s home run into the second deck in rightfield. It was his 18th of the season and 69th at Yankee Stadium (this one and its predecessor). One out later, Cespedes homered into the Yankees’ bullpen — despite Judge’s best efforts at the right-centerfield wall — to make it 2-0. Cespedes’ 15th glanced off the glove of the leaping Judge and hit off the top of the wall before settling into the bullpen. Judge used all of his 6-7 frame but came up just short.

The Yankees made it 2-1 in the fourth on Sanchez’s short sacrifice fly to left, with Hicks barely beating Cespedes’ off-line throw.

Yankees videos

Chad Green replaced Cessa and provided 2 1⁄3 innings of scoreless ball. Green didn’t allow a hit, walked one and struck out four. David Robertson (6-2) pitched a scoreless eighth. The Mets struck out 13 times.

“We need to win games,” Girardi said. “We’re chasing in our division. You look up and Boston loses. To come from behind is important. The contributions you get from Greenie tonight is extremely important and Robbie giving us that eighth inning. It is a big win.”

The Yankees used three relievers, all with closer-level stuff, and didn’t even have to use their closer. Terry Collins had to go to Robles for more than one inning in a tie game. Advantage, Yankees. Victory, Yankees.

“It’s certainly a difficult task for any team,” Collins said. “When you’ve got young players that aren’t used to seeing that kind of great pitching one after another, it’s really hard. But they’ve got a great bullpen and I think one of the things we’re going to get out of this series no matter what the outcomes are is our young players are going to learn what to expect when you’re facing a real good team.”