James connected on a jumper with 4:47 left to put the Heat ahead to stay at 92-86, but the Raptors didn't give up as Amir Johnson supplied a 3-point play and Jonas Valanciunas added a layup.
DeMar DeRozan's driving dunk with 1 minute left pulled Toronto to within 96-95, but he missed a potential go-ahead hook shot with 24.9 remaining.
James hauled down the rebound and sank two more free throws to seal the outcome as the Heat won for the fourth time in five games.
The Raptors had their season-best five-game winning streak despite 26 points and seven assists from DeRozan.
Chipotle plans first price increase in 3 years
Justin Bieber crashes Drake Bell's album release party