BOSTON — What a difference a year makes.

The Yankees head to Boston for a four-game set beginning Friday in command of the AL East and with the best record in the majors — pretty much where the Red Sox were last season.

And the Red Sox are trying to make a late surge to get into the playoffs as the second wild card.

Brett Gardner doesn’t know exactly what to make of the reversal.

“We’ve played better,’’ Gardner said. “How do you explain it? I can’t explain it. I look at their team. I know they’ve dealt with some things, like Chris Sale being shut down. But with all the guys we’ve been without, it’s something I can’t explain. Nobody could have predicted our injuries and for us to be in the position we’re in. But somehow, here we are.”

Where they are is with a 9.5-game lead over Tampa Bay in the division — as well as a whopping 16.5-game advantage over Boston, which remains on the outside looking in at the AL playoff picture.

In part because of their dominance throughout the year, the Yankees say they’re not all that focused on where their main rivals are in the standings.

“What are they, 15 games out?” Aaron Judge said. “That’s not what we’re thinking about. We’ve been set on winning the division since spring training, so this is what we expected.’’

But even Judge acknowledged the path to get to this point is not what he or anyone else planned on, with dozens of players on the IL and a seemingly endless supply of replacements who have played as well if not better than some of the regulars who got hurt.

“This isn’t the way we thought we’d navigate to get here, but we’re set up well,’’ Judge said.

Their sizable lead in the division should afford them the opportunity to configure their pitching however they want leading up to the ALDS.

“That’s part of the reason why Boston had so much success last year,” Judge said. “It’s not like they relaxed, but they could gear up for the playoffs. I talk to our hurt guys all the time about not rushing back. I tell them, ‘It’s not like September is the last month. We’ve still got two months left of baseball. Take your time and make sure you’re right for the postseason.’ That’s why winning the division is huge.”

And that’s why they have no intention of slowing down as long as there is a division title, as well as home-field advantage in the playoffs, to play for.

It’s also why Gardner expects the usual intensity at Fenway Park this weekend, despite the gulf between the teams.

“All the games are gonna matter,’’ Gardner said. “I can assure you, both teams want to win as bad as always.”

The Yankees find themselves pretty much where the Red Sox were in 2018, when they won an MLB-best 108 games en route to a title. But there eyes are still on October, where they want to advance beyond where they’ve been the last two seasons.

“I like where we are, and I don’t think we’re going to slow down,’’ Gardner said. “We’ve done it for five-plus months. And possibly getting guys back like [Luis] Severino and Dellin [Betances], [Giancarlo Stanton] and [Aaron] Hicks only strengthen our chances. We can still be better than we’ve been.”