MIAMI — Dwyane Wade jumped onto a courtside table and thumped himself on the chest three times. He took a victory lap, waving a towel. He got mobbed by teammates.

He’s been part of games that meant more.

But bigger moments — there haven’t been many, if any, than this one.

Wade’s one-legged, off-the-glass, straightaway 3-point heave as time expired lifted the Miami Heat to a 126-125 victory over the Golden State Warriors on Wednesday night, a game where the Heat wasted every bit of a 24-point lead and had to rally from four points down in the final minute.

“I’ve been in this position so many times and so many times you don’t make the shot,” Wade said. “And the one I make is a one-legged flick from my chest. It’s crazy. Great to do it in front of fans.”

Kevin Durant made one of two free throws with 14 seconds left, putting Golden State up by two. The Heat had no timeouts, no way to set up a play, and there was no way anyone could have drawn up what happened.

Wade brought the ball up, drove into the lane, stutter-stepped and lost the ball for a brief moment. He gathered it and shoveled it to Dion Waiters, who was double-teamed and couldn’t get off a shot. Waiters tossed it back to Wade, who shot-faked Durant in the air and then had his first try blocked by Jordan Bell.

Wade caught the rebound with about a second left.

Off the glass, for the win.

From there, bedlam.

The fans erupted in cheers. Some of the Warriors watched the replay on the overhead screens with a look of disbelief, and after a moment Warriors star Stephen Curry came over to offer congratulations after presumably their last head-to-head meeting before Wade retires after this season.

“I told Steph, ‘I needed this one on my way out. Y’all get enough,'” Wade said. “But it was cool. I think the one thing cool for me was I’ve got younger teammates that heard about some of the things you do but don’t always get an opportunity to see it.”

Wade scored 25 points to help Miami snap a six-game home losing streak.

“Sometimes you just need to be lucky,” Heat coach Erik Spoelstra said after giving Wade a long bear-hug in a jubilant postgame locker room. “We’ve had so many of these breaks go against us.”

Goran Dragic led the Heat with 27 points. Josh Richardson added 21, and Miami made 18 3-pointers.

Klay Thompson scored 36 points for the Warriors. Durant added 29 and Curry scored 24 for the Warriors, whose lead over Denver atop the Western Conference dropped to a half-game.

Golden State rallied from 19 down to win 120-118 at home on Feb. 10, and dug its way out of an even bigger hole this time — but couldn’t finish it off. Wade’s 3-pointer with 15 seconds left got Miami to 124-123, and he came up with one more when the Heat needed it most.

“Dwyane just hit an unbelievable shot,” Warriors coach Steve Kerr said. “It was going in as soon as it left his hand.”

Dragic had 25 points by halftime, getting 20 of those in the second quarter alone — setting Heat single-quarter and any-half records for a reserve. He had 11 points in a span of 69 seconds in the second quarter, and a pair of free throws with 2:59 left in the half put Miami up 69-45.

Against most teams, even in the first half, a 24-point lead might have been enough.

The Warriors, of course, are not most teams.

Back-to-back 3-pointers by Durant and Thompson helped Golden State get the lead down to 74-59 by halftime. The Warriors cut the lead to seven on two separate occasions in the third quarter, and kept whittling away in the fourth — getting within six when Draymond Green rattled in a 3-pointer from the right corner with 8:20 left, then 106-103 when Curry connected from deep on the next possession.

The Warriors led for all of 1:14 in the second half. Wade didn’t let them leave with the lead.

“There is something special about him making a play like that, this his last year in this building,” Curry said. “I’d much rather see him jumping on the scorer’s table when we’re not on the court. Deep down, it was cool to see even though we lost.”