TORONTO (AP) -- The Miami Heat had to work a little harder than they wanted for their ninth straight victory.
LeBron James scored 27 points, Dwyane Wade had 22 and the surging Heat beat the Toronto Raptors 90-83 on Friday.
Still, it didn't come easy for Miami, who watched a 20-point third-quarter lead whittled down to two points with less than five minutes to go in the fourth.
''We would have loved to push that huge lead up in the third and just keep it going but they've got some good players,'' James said. ''They got stops, we turned the ball over, we didn't execute and they got back into the game. But we finished it out.''
Heat coach Erik Spoelstra said his team became frustrated as they shot 4-for-18 from the field in the fourth, allowing Toronto back into the game.
''I told the guys we certainly have to get better when we have leads that are over 15, to be able to close out and focus and maintain that same type of intensity,'' Spoelstra said.
Wade was philosophical about enduring the Toronto comeback, calling the win both a confidence builder and a character builder.
''Those things happen, Wade said. ''You don't want it to happen too many times but you've got to catch yourself, and we were able to catch ourselves.''
James agreed with Wade, adding that he enjoyed the chance to be on the floor with the outcome up for grabs.
''You've got to have these types of games throughout the course of the season, the games that challenge you,'' James said. ''You see how you can execute, see who's going to show up late in the game and execute on both ends. These games are fun. I love the rest, but I hate sitting in the fourth quarter.''
James, who had six rebounds and three assists, said he was looking forward to a day off Saturday after injuring his back in a collision with Toronto's Tyler Hansbrough.
''It bothered me throughout the game,'' James said. ''That's definitely a step backwards, but we'll see what happens the next couple of days.''
Ray Allen and Michael Beasley each scored seven points and Chris Bosh fouled out with four points as the Heat won their 13th straight over the Raptors and their seventh straight in Toronto. Miami has not lost to the Raptors since Jan. 27, 2010.
''There were a lot of opportunities we didn't cash in on,'' Raptors coach Dwane Casey said.
DeMar DeRozan scored 25 points and Rudy Gay had 21 points and 11 rebounds for the Raptors, who lost their second straight. Kyle Lowry had 15 for Toronto.
DeRozan was unhappy that the Raptors didn't wake up until they were facing a huge deficit.
''We're a hell of a team when we get down 20, but we can't let it get there,'' he said.
Miami called time-out after back-to-back baskets by Lowry and DeRozan cut it to 83-79 with 5:24 left in the fourth quarter.
After DeRozan missed a pair of free throws, Gay grabbed the rebound and scored on a layup, cutting it to 83-81. James responded with a 3, pushing the lead to five, and Toronto missed its next four shots.
Gay had a chance to end the scoring drought when he went to the free throw line with 1:37 to play, but missed both attempts. James answered with a layup, pushing the lead to seven.
Toronto made just two of 10 free throw attempts in the final quarter, missing their first seven attempts.
''They helped us out a lot,'' James said.
James' only points in the first came on a reverse slam dunk, but Wade and Chalmers each had six for the Heat, who led 27-22 after one.
James scored eight in the second, including a pair of alley-oop dunks, and Chalmers also had eight as Miami took a 57-43 lead at halftime.
A fast-break dunk by James put Miami up 74-54 with 5:13 left in the third, but the raptors closed the quarter on a 16-4 run, making it 78-70 heading into the fourth.
Hansbrough needed two stitches to close a cut over his left eye in the first half, but he was able to return.
NOTES: The Heat enjoyed Thanksgiving dinner at James' Ohio home on Thursday. ... Quincy Acy returned for Toronto after missing the past three games with a sore right ankle.