Josh Donaldson hits a walk-off grand slam in the 10th inning,...

Josh Donaldson hits a walk-off grand slam in the 10th inning, giving the Yankees an 8-7 victory over the Rays. Credit: Jim McIsaac

Rallying from a seemingly insurmountable three-run deficit in the bottom of the 10th inning, the adrenaline rush of Josh Donaldson’s walk-off grand slam, the bat flip, the dugout emptying, the pinstriped party, transforming the dirt around home plate into a Bronx dance floor.

What the Yankees did in flipping the script late Wednesday/early Thursday — Donaldson crossed the plate at midnight to secure the 8-7 victory over the Rays — was a flashback to the team they used to be before the All-Star break sapped their mojo and had them start the second half with the second-worst record in the American League (8-17). The Yankees, incredibly, played even worse than those numbers indicated.

But Donaldson’s swing wiped away nearly all of the negative vibes, and the growing discontent outside the Yankees’ clubhouse quieted for the moment, however briefly. With that one vicious hack, the ball sailing deep into the rightfield stands, Donaldson — struggling himself — exorcised more than two week’s worth of demons for his team.

To say the Yankees needed that grand slam was the understatement of the year. They may look back when all this is wrapped up and point to that Donaldson blast as the most important swing of the entire regular season.

“Obviously, it’s not been easy for us,” manager Aaron Boone said. “But we’re in the fight. We’ve just got to keep fighting.”

During the first half, when the Yankees were dominating the sport, they built a reputation on comeback wins, a trait that spoke to the character of the 2022 club. It’s what made people view them as unbeatable at times — a relentlessness that ultimately rolled over the opposition.

But the magic disappeared at some point during the All-Star break, and the doubleheader sweep in Houston knocked them off-balance at the jump. Doubt began to creep in. The Yankees had lost 11 of 13 games before Wednesday’s series finale against the Rays as their division lead dropped to nine games — the lowest margin since June 15.

Things didn’t get much better Wednesday night as the Rays jumped to a 4-0 lead and the game was interrupted by an 63-minute rain delay in the seventh inning. But Anthony Rizzo led off the eighth with a home run that tied the score at 4 — matching the Yankees' entire run total of the previous four games — and the waterlogged fans who remained dared to hope.

Keeping the faith became much harder to do, however, when Aroldis Chapman got tagged for three runs in the top of the 10th. He was one pitch away from escaping a bases-loaded jam, but Francisco Mejia managed to punch a 101-mph fastball just inside the first-base line for a three-run double that put the Rays ahead 7-4.

“That was one of those gut punches with what we’ve been going through,” Boone said. “Especially when it felt like Chappy was kind of righting the ship there.”

It was a shocking blow for a Yankees team whose confidence level was dangerously close to E in recent days, and easily could have ended that game from a mental standpoint. Somehow it didn’t.

With Aaron Judge as the automatic runner at second base, Gleyber Torres — who homered earlier — slapped a single to rightfield and Rizzo drew a walk to load the bases. That set up Donaldson, who not only was 0-for-3 but also had been drilled on the wrist in the fourth inning (he was wearing a big wrap on his right arm postgame).

Donaldson swung and missed at a first-pitch fastball, but not the second, launching the 97-mph pitch high into the darkness. In looking up, he flipped the bat, then smiled.

“There’s not too many better feelings in the world,” he said. “As a kid, that's what we all put ourselves into these moments for. When I hit it and saw which direction of the field it was going in, I knew that it was gone.”

After the Yankees’ misery of late, however, there was a part of Boone that had to have visual proof to confirm what everyone surely believed from the moment of contact.

“I don’t know anything right now,” Boone said, smiling. “I felt like off the bat, like right away, I felt like it was a homer, but I needed to see it go over.”

Yes, it was all true. Donaldson was the hero, and the Yankees had snapped a three-game losing streak in the most dramatic way possible. But it’s still just one victory. There’s more work to do. A lot more.

“I think that’s who we are as a team,” Donaldson said. “I don’t think the last two weeks is who we are. I think that’s more of a blip than anything.”

If so, they’ll need to start proving that. All over again.