PHILADELPHIA >> Nick Castellanos sometimes amazes himself with intuition he can win a game on the final swing.

As he approached the plate with two outs in the ninth inning, with two runners on and the score tied, Castellanos had a hunch he could win Game 2 of the NL Division Series for the Philadelphia Phillies.

Even in the face of an 0-2 slider against Mets reliever Tylor Megill.

“I did like that pitch when I saw it,” Castellanos said.

Castellanos ripped a winning single that scored Trea Turner and sent the Phillies to a dizzying 7-6 win over New York on Sunday and evened the NLDS at one game apiece.

“I said to the guys, Rocky would be proud,” postseason star Bryce Harper said. “Never-die mentality. Just a great game.”

Castellanos, who led the major leagues this season with four walk-off hits, tossed his helmet and was mobbed by teammates on the infield as a game that seemed to slip away one inning earlier turned into one more comeback for the NL East champions.

His performance in Game 2 will live long in Philly sports lore. Castellanos had two big swings and misses in the fourth inning for an 0-2 count. He didn’t bite on a sweeper in the dirt and mouthed his displeasure when he heard boos from fans.

His tying homer in the sixth made it 4-all, and Castellanos scored the go-ahead run on Bryson Stott’s two-run triple in a three-run eighth that put Philadelphia ahead 6-4.

“He came up big for us a lot this year,” Stott said. “It feels like every walk-off hit is Nick, and that’s who he is. And his heart rate doesn’t get up, stays the same. And gets the swing off.”

Megill retired the first two batters of the ninth and walked Turner and Harper, who also homered and scored twice. Castellanos followed with the Phillies’ fifth career postseason walk-off hit.

“Just made a bad pitch, backed up on me,” Megill said.

After falling behind 0-2, Castellanos took a ball in the dirt, then pulled a hanging slider into left and sparked the towel-waving crowd at the ballpark into a frenzy.

“Unbelievable. Unbelievable,” Castellanos said. “If he blows a fastball by me, so be it. I’d rather that than swing at something in the dirt. It was incredible but the series is even. Now we go to New York and there’s a lot of baseball left.”

Game 3 is Tuesday in New York, the Mets’ first home game since Sept. 22.

“No excuses. It’s been hard, but here we are,” Mets manager Carlos Mendoza said. “I’m just looking forward to get back to Citi Field.”

Mark Vientos hit a pair of two-run homers for the Mets, who got solo shots from Pete Alonso and Brandon Nimmo.

Harper — who wore a “Showman” headband — snapped the Phillies out of their offensive malaise when he drove Luis Severino’s fastest pitch of the day, a 99 mph fastball, 431 feet into the shrubbery in dead center as fans roared.

“That was sick,” Harper said. “Best fanbase in the world.”

Now it’s off to New York.

“Both teams, man,” Harper said. “Punch for punch.”