The NBA plans to make San Antonio pay for resting four stars.

The Miami Heat almost could not.

Ray Allen’s 3-pointer with 22.6 seconds left gave the Heat the lead, LeBron James finished with 23 points and the Heat rallied late to beat the Spurs, 105-100, Thursday night in Miami — needing to dig deep despite San Antonio’s decision to have four standouts resting at home in a move that irked commissioner David Stern.

Advertisement - Continue Reading Below

Allen scored 20 points, Dwyane Wade added 19 and Chris Bosh finished with 18 points and 12 rebounds for Miami, now 7-0 at home.

Gary Neal had 20 points for the Spurs, who played without Tim Duncan, Tony Parker, Manu Ginobili and Danny Green. The Spurs’ top foursome was sent back to San Antonio by coach Gregg Popovich, who said the move was in his team’s best interest. Stern wasn’t happy about it, calling the move ‘‘unacceptable’’ and saying that sanctions against the Spurs will be forthcoming.

Tiago Splitter scored 18 points, Nando De Colo added 15, Boris Diaw scored 12 and Matt Bonner had a 10-point, 10-rebound night for San Antonio, which finished a six-games-in-nine-nights road trip with a 5-1 record.

The Spurs led by 7 with about 5 minutes left and were up, 98-93, after Neal made a 3-pointer with 2:14 remaining.

The Heat finished on a 12-2 run, needing yet another late-game rally.

But all anyone will likely remember from this one is Popovich’s decision — and whatever Stern does as a result.

‘‘I apologize to all NBA fans,’’ Stern said. ‘‘This was an unacceptable decision by the San Antonio Spurs and substantial sanctions will be forthcoming.’’

Stern’s statement was released roughly the same time as tip-off in Miami for the nationally televised game.

The Spurs’ five starters came into the game averaging a combined 23.6 points, or 1.6 points less than James averaged entering Thursday night.

And when the Heat ran out to a 16-6 lead, it seemed as though a blowout was in the offing. After all, even the oddsmakers in Las Vegas expected it to be that way — the Heat were favored by 6 points in most sports books before the news broke that the Spurs’ regulars were resting, after which the line swelled to 13.

Apparently, no one told the Spurs that the second-string was supposed to play second-fiddle.

San Antonio closed the first quarter on a 21-6 run, taking a 27-22 lead after the period, and simply did not go away. The Spurs led by as many as 7 at one point, and after James Anderson made a pair of free throws with 0.6 seconds left in the third, San Antonio held a 76-73 lead heading into the final 12 minutes.

But once again, James-to-Allen proved magical for Miami.

With the Heat down by 1, James nearly lost the ball in the lane, collected himself and kicked it out to Allen, who connected from the left wing to put Miami ahead to stay.