Fans cheer and hold up American flags during the seventh...

Fans cheer and hold up American flags during the seventh inning of a game between the Yankees and the Mets at Yankee Stadium on Friday. Credit: Jim McIsaac

The emotions flipped quickly Friday night at the Stadium.

Appropriately so.

Mere seconds after the conclusion of a poignant pregame ceremony commemorating the 25th anniversary of the terrorist attacks of Sept. 11, 2001, came the pregame introductions of the Mets and Yankees.

The Mets, Juan Soto especially, were loudly booed.

The Yankees, Aaron Judge in particular, were loudly cheered.

And it was the Yankees who kept that going, scoring once in the first and getting a three-run homer from Cody Bellinger with two outs in the second to send them on their way to a 6-4 victory in front of a sellout crowd of 47,410 at the Stadium that included managing general partner Hal Steinbrenner.

The Yankees (85-62), who also got home run No. 37 from Ben Rice (three hits) and a rickety five-out save from David Bednar, are a season-high 23 games over .500. They stayed three games behind the AL East-leading Rays.

For one night, the Yankees cooled off the Mets (68-79), who came into the night 21-12 since the Aug. 3 trade deadline. That .636 winning percentage was tied for the second-best mark in the majors in that stretch.

The Yankees took control early behind Bellinger’s 14th homer and a strong outing from lefthander Carlos Rodon (6-3, 2.94 ERA), who allowed two run (one earned), three hits and a walk in 6 1⁄3 innings, striking out eight. Rodon has allowed one earned run or fewer in eight of his last 12 starts.

Bednar, brought on with the bases loaded and one out in the eighth to protect a 5-2 lead, allowed a sacrifice fly by Marcus Semien that made it 5-3. Ryan McMahon’s looping RBI single in the bottom of the eighth bumped the Yankees’ lead back to three runs, but Bednar allowed a leadoff homer into the second deck in rightfield in the ninth by A.J. Ewing that made it 6-4.

Francisco Lindor singled with one out, bringing up Soto, a Yankee in 2024 before accepting a record $765 million free-agent contract from the Mets. Soto, who went 1-for-5 with two strikeouts, bounced into a 3-6-3 double play started by Paul Goldschmidt to end it and give Bednar his 33rd save in 36 chances.

“[The Mets] hung in there and we couldn’t put the game away,’’ Yankees manager Aaron Boone said. “Obviously, got a little dicey there, but we’re able to hang on.”

Rodon departed with one on and one out in the seventh and Paul Blackburn allowed an inherited runner to score, which cut the Yankees’ lead to 5-2. Blackburn loaded the bases with two outs and Boone called on lefty Brent Headrick to face the switch-hitting Lindor. He smoked one back up the middle, but Headrick snagged it for the third out.

Headrick recorded only one out in the eighth, turning over the bases-loaded jam to Bednar.

Heralded Mets righthander Nolan McLean (11-9, 3.24), allowed five runs and a season-high 10 hits in five innings in which the Yankees ran his pitch count up to 101.

Rice and Bellinger led off the bottom half with singles and Judge walked to load the bases. Luis Garcia Jr. (three hits) lined to second, but Spencer Jones’ RBI single made it 1-0.

The Mets tagged Rodon for an unearned run in the top of the second, but the Yankees struck back with a two-out rally in the bottom half. Anthony Volpe — who had three hits and five RBIs, including a grand slam, in his return to the big leagues Thursday night — started the rally with a single. Rice singled and Bellinger drove a full-count curveball 377 feet to right to make it 4-1.

Rice’s opposite-field homer to left in the fifth made it 5-1.

Boone said of the atmosphere: “It was great. Obviously, as a club we’re playing for a lot, but having some of the people involved today back and part of the pregame ceremonies, it felt special. The energy in the crowd was special. I’m glad it felt like, I don’t want to say celebration, but it felt like what you’d want a ballgame to feel like. So I thought a lot of people were here having a great time on what for many is a difficult day.”

Said Rice: “It’s an emotional day. Obviously such a tough day for the city, and just happy we were able to provide some positivity today on such a tough day.”

Mets interim manager Andy Green said: “The ceremony at the beginning was really well done. I think we honored everybody as well as possible today. Certainly wish the game outcome was different than it was, but special to be a part of. The crowd was definitely into it from the jump.”

And McLean: “It was awesome. Awesome fans, awesome city. I think that’s ultimately what’s most important about tonight. People who died trying to help others  and the people who were in those buildings. It’s awesome to see that many people show up and support it.”

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 6 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME