The Knicks thought they had left the Cavaliers and LeBron James for dead late in the third quarter with what appeared to be a stirring, we-won’t-back-down performance.

Instead, on a night he was booed relentlessly for his off-putting remarks about rookie point guard Frank Ntilikina, James grabbed back the night. The Knicks suffered an epic collapse in losing all of a 23-point lead as the Cavaliers prevailed 104-101 before a heartbroken Garden crowd.

James sank the dagger — a step-back, tiebreaking 3-pointer over Kristaps Porzingis with 1:23 left that gave the Cavs their first lead since the first quarter and sent them to their improbable comeback.

James finished with 23 points, 12 assists and nine rebounds.

Trailing by 15 points entering the fourth, James finally showed up as playmaker extraordinaire and Kyle Korver scored 19 fourth-quarter points to finish with 21.

Behind Ntilikina’s six steals, the Knicks built a 23-point lead in the third period and the Garden was rocking before it all came apart at the seams. Porzingis was in foul trouble early and had a sluggish night of 20 points, and missed two key free throws down the stretch with the Knicks up three.

Trailing by three, the Knicks were still in it but Dwyane Wade collected a giant offensive rebound with 12 seconds left and Korver hit the game-sealing free throws. It still got scary with four seconds when James, his team up three, missed both free throws but collected the offensive board.

In taking a 51-38 halftime bulge, the Knicks and Ntilikina played inspired defense, clearly angered by the remarks James made Saturday night in Dallas.

James claimed the Knicks blew it by taking Ntilikina over Dennis Smith Jr. The French rookie notched five steals in the first half — and one shove of James. It was the first time a Knicks rookie had notched six steals since Mark Jackson in 1987.

James was booed during pregame introductions and every time he touched the ball. But the place didn’t get into a complete frenzy until center Enes Kanter stuck up for Ntilikina late in the first quarter, getting in James’ craw, igniting an altercation.

It began after a James dunk after which Ntilikina went to gather the ball to inbound. James stood in his way and Ntilikina pushed him. As James looked to get back at Ntilikina, Kanter came rushing in and started jabbering in James’ face and the two players exchanged shoves.

James and Kanter both wound up with technical fouls. Before the game, Kanter had come to Ntilikina’s defense on Twitter and James retorted the Turkish center “always has something to say.’’

Kanter finished with 20 points, and Tim Hardaway Jr. added 28.

Despite Porzingis’ early foul trouble, the Knicks roared in the second quarter, knocking away ball after ball with Ntilikina notching four of the Knicks’ seven steals in the period.

But it was all for naught as the Knicks took their foot off the pedal in the final period to fall to 7-6.

In the fourth, James was running the show and spreading the ball around. His runner while getting hip checked by Jarrett Jack fell through and he flexed his right bicep muscle. It made it a seven-point game.

Korver got a lucky bounce on a 3-pointer that first hit iron, putting the deficit at 3. With 3:25 left, Korver got the Cavs within 94-92 on a 3-pointer from up top with Hardaway late to cover.