Dwyane Wade added 20 points for the Heat, who had to overcome a 16-point deficit to beat the Knicks for the first time in three tries this season. Chris Bosh bounced back from a dismal first half to finish with 16 points.
The defending NBA champions won their sixth straight on the road by controlling the final minutes against a team that had a pair of 20-point victories over them this season and looked ready to run them out of the building again.
But James shook off a third-quarter leg injury and was back in top form by the finish, putting it away by coming up with a steal and throwing down a dunk with 23 seconds left.
Carmelo Anthony scored 32 points for the Knicks, who had their three-game winning streak snapped.
Jason Kidd emerged from a lengthy slump to finish with 14 points, eight rebounds and six assists for the Knicks. J.R. Smith had 13 points and 12 rebounds but shot 5 of 18 from the field.
The Heat matched their 14 straight wins during the 2004-05 season and finally beat one of their closest pursuers in the Eastern Conference after dropping their first four against the Knicks and Indiana Pacers.
James landed awkwardly when he was fouled trying to catch a lob pass in the third quarter and was trying to loosen his left knee or leg after. He looked fine in the closing minutes, making key plays on both ends of the floor.
Bosh tied it at 87 and Wade's basket with 4:29 gave Miami the lead for good. James then blocked Tyson Chandler at the rim and hustled down the floor to put back a Miami miss, making it 91-87.
The Knicks twice were within two, but James scored on a drive the second time. Bosh followed with a jumper for a 97-91 advantage, and after two free throws by Raymond Felton, James ended the Knicks' final hopes when he stepped in front of pass headed toward Anthony and broke in alone for the slam as Anthony hung his head near half court.
The Knicks beat Miami here by 20 in their season opener and won again in Miami in early December by 20, even while playing without Anthony because of a cut on his finger that required stitches.
This looked headed for another blowout.
Kidd missed all 14 3-point attempts in the last three games and had been in a 7-for-49 slump behind the arc since Feb. 1, finally losing his starting job before Friday's victory at Washington.
But he made a 3 early in the second quarter, then hit three more during a 20-10 surge that turned Miami's one-point lead into the Knicks' 49-40 advantage.
The Knicks then rattled off eight in a row late in the period, opening a 59-43 lead on a free throw by Iman Shumpert with 36 seconds to go. The only concern for the Knicks came when Anthony went to the locker room before the half ended after being hit in the ribs, but was back when the second half started.
Kidd would've been perfect in the period, but was credited with a shot attempt when he jumped to save a pass that was going out of bounds along the sideline and just heaved it toward the basket in one motion.
The Knicks' two victories over the Heat came during their 18-5 start, when they seemed championship capable. But they had been just 17-15 since, falling into a tie for second with Indiana in the East, and were being frequently dismissed as a serious threat to the Heat.
Not by Miami coach Erik Spoelstra, though.
"We know that they're a direct rival of ours right now and they've kicked our butt twice," Spoelstra said before the game. "Tough in this building and despite what anybody said about them this year, or the struggles, perceived struggles that they may have had in the last few weeks, they're the sixth-best team in the league, second in the East and they've had moments where they've beaten the best and have played as well as anybody in this league."
They did again for half the game, but Miami's a far different team now than it was in December.
Bosh had eight quick points in the third quarter after a two-point, 1-of-6 first half, as the Heat got within four. The Knicks regrouped and pushed the lead back into double digits, but Miami then scored the last six of the period, cutting it to 77-73 on Shane Battier's 3-pointer with 1.8 seconds to go.
Miami finally caught up at 79-all when James nailed his second straight 3-pointer, stomping his feet forcefully as he walked away following the second with 10:04 to play.
NOTES: Juwan Howard was inactive, a day after the Heat re-signed the 40-year-old forward who finished last season with them. "To be honest, it felt a little bit strange not having him with us," Spoelstra said. "It makes sense, it feels right." ... Knicks coach Mike Woodson said forward Kenyon Martin will be with the Knicks beyond the expiration of his first 10-day contract.