MIAMI -- Kawhi Leonard scored 30 points, Danny Green's 3-pointer with 22.7 seconds left put Toronto ahead for good and the Raptors improved the NBA's best record to 26-10 by topping the Miami Heat 106-104 on Wednesday night.

Green had 18 points and Fred VanVleet added 16 for the Raptors, who survived a wild fourth quarter that saw 12 lead changes and four ties. Miami had three shots on the game's final possession, with Dwyane Wade and Justise Winslow missing 3s and Wade having a chance at a tip-in that wouldn't fall.

Winslow scored 21 points for Miami, which saw its five-game winning streak snapped. Josh Richardson scored 17 and Hassan Whiteside scored 16 for Miami, which was 6 for 12 from the foul line -- while Toronto was 19 for 23.

James Johnson and Tyler Johnson each scored 12 for the Heat, while Wade had 10. Pascal Siakam added 10 for the Raptors.

Winslow's layup with 35.2 seconds left put Miami up by one, and on the next Toronto possession Green found himself wide-open in the right corner -- nearly the identical spot from where Ray Allen hit a 3-pointer to deny Green and Leonard the 2013 NBA title when they were with San Antonio.

Green connected, the Raptors got the game's last stop and escaped to move to 7-0 against the Southeast Division this season.

Miami led 58-44 at the half and extended the lead to 17 early in the third quarter, before Toronto went to a zone -- the defence that the Heat have been using so well of late -- and the game changed. VanVleet made three 3s and had 11 points while Leonard added 10 in what became a 31-12 run over the last 8:10 of the quarter by the Raptors, and they took an 81-79 lead into the fourth.

Winslow made a wild layup for a 99-93 lead that came after an 8-0 Miami run -- and the Raptors needed about a minute to respond with a lead-taking 8-0 run of their own. VanVleet connected on a 3, Siakam added a three-point play and Leonard drew a blocking call against Winslow that the Heat didn't like with 1:19 left that he turned into a pair of free throws and a 101-99 Toronto edge.

TIP-INS

Raptors: It was Leonard's first game in Miami since Oct. 30, 2016. The last time he lost a game on the Heat court was Game 7 of the 2013 NBA Finals. ... Even the Heat were puzzled why Toronto had Dec. 25 off for the 17th consecutive year, since it wasn't exactly unexpected for them to be good. "I just don't understand why they didn't have a Christmas game," Wade said.

Heat: Rodney McGruder was back in the starting lineup, after missing his first game of the year Sunday in Orlando with an illness. ... Miami debuted its "Sunset Vice" uniforms, their perk for making the playoffs last season, with laser fuchsia the primary colour. ... Whiteside was 0 for 3 from the foul line, and is now 5 for his last 36.

LOWRY OUT

The Raptors were again without point guard Kyle Lowry, whose back tightened up Wednesday morning. Lowry has now missed five of Toronto's last six games, the other four absences caused by a thigh issue.

ROOKIE PRANK

Yante Maten, one of Miami's two-way players, got to lead the team onto the floor for pregame warmups. He ran out, turned and saw no teammates with him -- they all stayed back for about a minute in an oft-used prank, enjoying a good laugh. To his credit, Maten was laughing as well.

UP NEXT

Raptors: Visit Orlando on Friday.

Heat: Host Cleveland on Friday.