Castellanos 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.
Megill retired the first two batters of the ninth and walked Harper, who also homered and scored twice. Castellanos, who also homered, followed with perhaps the hit of his Phillies' career. He fell behind 0-2, took a ball in the dirt, then pulled a hanging slider into left and sparked the towel-waving crowd at Citizens Bank Park 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.
"Punch for punch the whole game," Harper said. "That's a big win going 1-1 into New York. I expect that to be a pretty hostile environment and we're looking forward to that."
In just the second postseason game between the NL East rivals, the Mets and Phillies were pushed from pillar to post over the final four innings, each game-changing swing topped by one even more emotional.
Mark Vientos hit a pair of two-run homers for the Mets, who got solo shots from Pete Alonso and Brandon Nimmo.
Harper's two-run homer and Castellanos' solo drive in a three-pitch span from Luis Severino sparked the Phillies' comeback from a 3-0, sixth-inning deficit.
After Nimmo's seventh-inning homer off Orion Kerkering gave New York a 4-3 lead, Bryson Stott lined a go-ahead, two-run triple down the right-field line on his 27th birthday after Harper and Castellanos singled off Edwin Díaz in a three-run eighth.
Stott scored on grounder for a 6-4 lead, but Vientos hit a two-run homer off Matt Strahm, an All-Star lefty who failed the Phillies for a second straight game.
Harper- snapped the Phillies out of their offensive malaise when he homered 431 feet into the shrubbery in dead center as fans roared.
UP NEXT
It's an off day Monday. The Phillies send RHP Aaron Nola to the mound Tuesday in Game 3 in New York. The Mets will start LHP Sean Manaea.