On Sept. 2, the Yankees had just a one-game lead over the Twins for the top wild-card spot and were ahead of the Angels by only 2½ games for the second wild card.

At that point, making the postseason was far from a guarantee.

By the time they finished their series sweep of the Twins on Wednesday, the Yankees were up by seven games on Minnesota and in prime position to at least host the AL wild-card game on Oct. 3.

Perhaps the most significant part of the resurgence has been Aaron Judge, who has brushed off his second-half slump over the last two weeks and has looked very much like the player who dominated baseball prior to the All-Star Game.

From the beginning of the second half until Sept. 2, Judge was 28-for-159 with just seven homers. Over the course of 46 games, he struck out 70 times and had an OPS of .676, as the Yankees went 26-20 during that stretch.

In 16 games since then, the right fielder is 15-for-53 with eight home runs. While he has also whiffed 20 times in those 73 plate appearances, he has an OPS of 1.212. Not surprisingly, the Yankees are 12-4.

Judge called the turnaround “part of the ups and downs of a baseball season,” but there could be another factor.

For weeks, Judge walked around the Yankees’ clubhouse with a giant ice pack wrapped around his left shoulder after games.

The 25-year-old is not one to discuss injuries, but the shoulder ailment likely can be traced to him flipping over the wall down the right-field line at Fenway Park in April. Since then, the ice pack was an occasional — and sometimes frequent — sight.

Recently, there’s been no sign of the ice pack.

Asked if the shoulder injury had impacted his swing and it not being much of an issue anymore, and the reason for the recent rise in productivity, Judge wouldn’t reveal much.

“It’s tough to say,’’ he said. “You still try to go out there, even if you’re 70 percent. Some guys are only 50 percent and you have to make it work.”

So what percentage would Judge consider himself now?

“I’ll see when I get out there,” Judge said.

Whatever the reason, the Yankees’ lineup looks far different when Judge is hitting like he has been this month.

He hit a home run on an 0-2 count for the first time in his career Wednesday, his 45th homer of the season.

As the Yankees prepare for a three-game series in Toronto, Judge has had success against Blue Jays pitching this season, but in seven games at Rogers Centre in 2017, he has gone deep just once in 32 plate appearances.

Still, he’ll take his chances, given how well he’s playing.

“I’m feeling pretty good,” Judge said. “Whenever you feel good, you play good.”

He expects to take something from the struggles he had over the summer, when he wasn’t healthy.

“Everyone has bumps and bruises throughout the season, so it’s not a big deal,’’ Judge said. “You just have to play. You’ve got to learn how to play with it.”

In the meantime, Judge is back to being one of the most feared hitters in the game.

“Hopefully you’re hot at the right time,” Judge said. “This is the time, the end of the year. It’s starting to get pretty exciting.”