"Now I'm going to be able to sleep good tonight," said Raptors guard DeMar DeRozan, who had 18 points in the 102-92 Toronto win before a sellout of 19,800.
The Raptors (39-26) came into the game having lost four straight and nine of their last 10 on a road-heavy stretch.
"They say when it rains, it pours," DeRozan added. "And we were in a shower for a while."
Kyle Lowry had 19 points, eight assists, eight rebounds and a career-high seven steals for Toronto — the first player in the NBA this season to record eight rebounds, eight assists and seven steals in a game.
"I thought he was back to old Kyle," said Toronto coach Dwane Casey. "Moving the ball. He made his shots, made his threes. That was huge, that opens up the floor when you do that. But I was just as impressed with our defence as much as anything else."
Miami (29-36) had won the last 16 straight meetings with the Raptors. Toronto's last victory came Jan. 27, 2010, when injured Heat star Chris Bosh played for the Raptors and DeRozan, now a five-year veteran, was a rookie.
Dwyane Wade, who has scored at least 25 points in his last five games, led a sputtering Miami offence with 25. The Heat, who were 5-of-23 from three point-range, closed the gap with a late 15-4 run.
Miami had 20 turnovers, contributing to 21 Toronto points.
"We just didn't play well," said Heat coach Erik Spoelstra. "Turnovers were especially crippling and (we) could never get into a very good rhythm."
Twelve of DeRozan's points came from the free-throw line. Lowry had the crowd on its feet with a moonshot three-pointer that extended the lead to 20 points midway through the final quarter.
"We played with a good sense of urgency tonight," said Lowry, who had shown his emotion at the club's sinking fortunes in a loss to San Antonio earlier in the week.
The win was a welcome tonic for Toronto, which went into the all-star break on a 10-3 run but is just 3-9 since. Six of Toronto's next nine games are at home.
"I think we got a false sense of security after the Atlanta game, beating them by whatever we beat them by," said Casey, referring to a 105-80 victory coming out of the all-star break. "But again every night's a hard night and we're not good enough to play a half or three quarters. We've got to play as many of the 48 (minutes) as we can to be successful on both ends of the floor."
Battling for a playoff spot, the Heat were in their own funk Friday. Starters Henry Walker and Hassan Whiteside missed all seven shots they attempted in the first quarter. Miami made just seven of 19 shots while Toronto was good on seven of 22 in a first quarter that ended in a 21-18 Raptors lead.
A 16-4 run in the second quarter helped Toronto stretch its lead to 41-27. The Heat missed their first nine three-point attempts while the Raps made six from distance to lead 50-41 at the half.
Toronto's Greivis Vasquez was assessed a flagrant foul early in the fourth on a play that sent Tyler Johnson crashing to the floor. But Vasquez was showing his dance moves later in the quarter after a long three-pointer.
Raptors big man Jonas Valanciunas was given the night off after his wife gave birth to a baby boy.
Follow @NeilMDavidson on TwitterSuggest a correction