The Phillies barely dented Noah Syndergaard last night. It was Yoenis Cespedes that Syndergaard had to worry about.

Syndergaard was leading off third base in the fourth inning when Cespedes rocketed a foul line drive the pitcher’s way. Fortunately for the Mets, the helmeted Syndergaard ducked just in time to prevent getting skulled by the screaming liner.

“You don’t want to know what I thought,” manager Terry Collins said. “Two weeks ago, that would have hit him right in the middle of the back. Or on the right elbow. That would have been another good spot.”

Said Syndergaard: “That was just all reflex. I don’t think it was really anywhere near me, but when it’s coming that fast . . . I don’t know how unathletic I looked there. Just trying to hit the deck.”

Fortunately for the Mets, Cespedes finished the at-bat by clubbing another screaming line drive. This 109-mile per hour missile reached the second deck in leftfield for a three-run home run and the Mets went on to their sixth win in seven games, 12-1, over the Phillies before 35,832 at Citi Field.

Cespedes’ home run gave the Mets a 5-1 lead. Syndergaard and the Mets’ rejuvenated offense did the rest.

advertisement | advertise on newsday

Syndergaard (12-7), who was coming off an eight-inning, two-hit, no-run performance against the Giants, again allowed only two hits, this time in seven innings. One of the hits was a home run by Freddy Galvis in the third inning that gave the Phillies a 1-0 lead.

Asdrubal Cabrera answered in the bottom of the inning with his third home run in two nights. Jose Reyes (3-for-5) led off with a single before Cabrera hit an opposite-field, two-run homer to left-centerfield off Jeremy Hellickson (10-8) to give the Mets the lead. It was Cabrera’s 16th home run of the season, one more than he hit last year with Tampa Bay.

Syndergaard started the Mets’ three-run fourth with a booming one-out double to center. Reyes followed with a single before Cabrera popped to third for the second out.

Cespedes’ homer was his 26th of the season.

Syndergaard retired 11 in a row before Maikel Franco singled to right with one out in the seventh inning. Syndergaard struck out Ryan Howard for the third straight time and got Cameron Rupp on a weak fly on his 104th and final pitch.

Mets videos

Syndergaard walked two and struck out seven. He improved to 4-0 with a 1.03 ERA in four starts against the Phillies.

The Mets put the game away with a six-run seventh. Alejandro De Aza had a two-run double that was nearly a grand slam. No matter. Kelly Johnson hit a pinch hit grand slam to make it 11-1.

It was Johnson’s fourth pinch hit home run of the season and the Mets’ 86th home run at Citi Field, a franchise record for the eight-year-old ballpark.

Neil Walker made it 87 when he hit a solo shot in the eighth. Walker tied his career high of 23 home runs set in 2014.

“There’s some confidence in there right now,” Collins said. “Some guys are coming through that hadn’t been coming through. We’ve been talking endlessly about not getting hits with runners in scoring position. Right now, we are. It looks like a completely different team . . . The the energy’s just different in the room right now.”

advertisement | advertise on newsday

“The energy that we’re in right now,” Cespedes said, “it’s taking us back to the last two months of last season.”

With the Cardinals’ 3-2 loss to the A’s, the Mets are now 2½ games back of St. Louis for the second NL wild-card slot.