James led the scoring for the Cavs as the Raptors's six-game winning streak came to an end.
James led the scoring for the Cavs, who also saw Kevin Love pour on 28 points with 14 rebounds as the Raptors's six-game winning streak came to an end.
The Cavs had looked to be easing to victory after opening up a 15-point lead in the fourth quarter.
But a determined Raptors fightback, which saw them move to within four with two seconds left, ensured the game went down to the wire after Kyle Lowry's three free throws.
Kyrie Irving meanwhile scored 24 points and Channing Frye contributed 10 off the bench for Cleveland.
DeMar DeRozan topped Toronto's scorers with 31 points while Lowry finished with 24 points and nine assists.
The win saw the Cavaliers improve to 14-5 in the overall Eastern Conference race, ahead of Toronto (14-7) and Boston (12-9).