BOSTON — To a man, each player who was here a year ago, when the Yankees had their season ended by the Red Sox in the ALDS, said they didn’t place much importance on knocking Boston out of the AL East race on Monday night.

But there was “New York, New York’’ blaring from the visiting clubhouse after the Yankees beat their rivals, 5-0 at Fenway Park.

“It’s a good song,’’ Austin Romine said of the music that caused some controversy when Aaron Judge played it as the Yankees left Fenway during the playoffs last October — only to lose the series.

This is a much different season, though.

It’s one that has seen the Yankees emerge as perhaps the best team in the league and Boston, less than a year removed from a title, already undergoing a front-office shake-up after winning three straight AL East races.

And if the Yankees want to finish the job, their next goal will be to wrap up the division. Their magic number dropped to nine over second-place Tampa Bay with Monday’s win — behind another outstanding performance from James Paxton.

The left-hander delivered another scoreless start, this one 6 ²/₃ innings after he pitched seven scoreless against Texas his previous time out.

“He’s the best pitcher in the game,’’ Judge said. “He’s getting right at the right time.”

He got all the offense he needed from Romine and Gio Urshela, who each hit solo homers.

Paxton had his worst outing of the year at Fenway on July 26, when the Yankees’ entire rotation seemed to be imploding. In that game, Paxton allowed seven runs — all earned — and it was Paxton’s second consecutive start in which he’d given up seven runs.

“Maybe the best thing that happened to him was that game,’’ Boston manager Alex Cora said. “Because he kind of changed the script. He’s not relying only on the cutter. He’s using his breaking ball to get ahead and then he’s using that two-seam fastball away to get big outs and get guys on soft contact.”

Paxton has won each of his eight start since then and allowed two earned runs or fewer in his past four.

The Yankees took the lead in the fifth on Romine’s opposite-field solo homer to right off Eduardo Rodriguez.

Boston threatened in the sixth with two out on a J.D. Martinez walk and Christian Vazquez single to left on an 0-2 pitch. Paxton recovered to get Sam Travis to ground to third to end the inning.

Urshela’s homer added a run in the seventh against Darwinzon Hernandez. It was Urshela’s first start since returning from the injured list with a strained left groin.

Later in the inning, Romine doubled and scored on a single by DJ LeMahieu.

Paxton retired the first two batters in the seventh and then walked Bradley to end his night, but Zack Britton got the final out of the inning.

Cory Gearrin pitched a scoreless eighth and the Yankees tacked on another run in the ninth before Tyler Lyons finished it.

“I’m in a good spot,’’ Paxton said. “I feel great and want to stay there and go into the postseason feeling this way.’’

Aaron Boone feels the same.

“We’re coming down the stretch and hope to have a lot of baseball left,’’ the manager said. “You like to see guys at their best this time of year.”

And if they can make things more difficult for their rivals, that’s fine.

Judge said eliminating the Red Sox from the AL East race “wasn’t even on our radar, to be honest. We wanted to come here and continue our success. Our goal is to dominate every series.”

And they’re approaching their first division title since 2012.

“That’s what we’re shooting for,’’ Judge said. “We want to be the best team in the AL East and the best team in the AL. We have to win the division first. We’re not there yet, but we’re getting close.’’