Danny Green rattled in the go-ahead basket with 22 seconds remaining as the Toronto Raptors improved to a NBA-best 26-10 record with a 106-104 win over the Miami Heat on Wednesday.

“I just ran to the corner and somehow I was wide open,” said Green. “They swung it, they found me and I had enough rhythm to knock down the shot.”

Kawhi Leonard scored a team-high 30 points, Green finished with 18 and Fred VanVleet scored 16 for the Raptors, who held on for the win despite a final quarter that featured 13 lead changes.

“We did a good job against (Miami’s defence) and we threw a little zone of our own at them and that really was a bit of a turning point in the game as well,” Raptors head coach Nick Nurse said.

Miami’s Dwayne Wade missed two chances to extend the game, including an easy tip-in under the basket as the final buzzer sounded.

Besides Wade, Justise Winslow also missed a key three-point attempt late in the game.

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.

The Heat were six for 12 from the free throw line, while Toronto was 19 for 23.

Miami led 58-44 at the half and extended the lead to 17 early in the third quarter.

But then the Raptors took over as VanVleet made three threes and had 11 points, while Leonard added 10 in what became a 31-12 run over the last eight minutes of the third, giving Toronto a 81-79 lead heading into the fourth.

Elsewhere, Joe Harris made a clutch layup with three seconds left in the second overtime as the Brooklyn Nets outlasted the Charlotte Hornets 134-132.

Harris finished with a season-high 27 points and Spencer Dinwiddie had 37 points and 11 assists for the Nets, who won for the ninth time in 10 games.

Rondae Hollis-Jefferson finished with 16 points and 15 rebounds, and rookie Rodions Kurucs had 13 points and 12 boards.

Kemba Walker scored 35 points and Jeremy Lamb added 31 points in the opener of a home-and-home series.

Harris grabbed a loose ball near midcourt and drove in for the tie-breaking layup. Charlotte had two chances to send the contest to overtime but Monk missed on their last possession.

Also, DeMar DeRozan had 30 points, LaMarcus Aldridge scored 27 and the San Antonio Spurs beat the Denver Nuggets 111-103.

Bryn Forbes added 15 points for the Spurs, who have won eight of their last 10 games.

Juancho Hernangomez had 27 points for the Nuggets, who dropped to 21-11 on the season and lost their second consecutive game.

Denver still leads the Northwest Division by a half-game over Oklahoma City.

In Orlando, Devin Booker had 35 points, eight assists and seven rebounds as the Phoenix Suns defeated the Orlando Magic 122-120 in overtime.

T.J. Warren added 24 points, including all four Phoenix points in overtime. Kelly Oubre scored had 19 points and Josh Jackson added 10 for Phoenix.