MIAMI -- Lou Williams scored 29 points, DeMar DeRozan added 24 and the Toronto Raptors put the Miami Heat on the brink of playoff elimination with a 107-104 victory Saturday night.

Greivis Vasquez and Kyle Lowry each scored 12 points and Patrick Patterson had 11 for the Raptors, who clinched home-court advantage in the first round of the playoffs.

Dwyane Wade scored 30 points for the Heat, who can only get to 37 wins -- the number that Brooklyn and Boston are already at, putting them in the No. 7 and No. 8 spots in the Eastern Conference race. Goran Dragic scored 22 points for Miami and Hassan Whiteside finished with 16 points and 18 rebounds.

But Whiteside also missed 12 free throws, going 4 for 16, and as a team the Heat went 24 of 44 from the line.

Williams hit a 3-pointer with 31.2 seconds left to put the Raptors up by five, and that just about sealed not just the game but Miami's playoff fate. The Heat must win their last two games, and get a ton of help to reach the post-season for the seventh straight year.

It was Toronto's first road win over the Heat since Nov. 19, 2008, ending a 10-game slide on Miami's home floor. The win was Toronto's 48th of the season and 22nd on the road, both tying franchise records.

The teams were tied at 58 at the break, with Williams doing what he does as well as just about anyone -- coming off the bench and giving the Raptors a spark.

Toronto had 31 points in the second quarter, and Williams had 17 of them. He made five of six shots from the field and all five of his tries from the line in a span of just over 9 minutes. Whiteside and Wade did their part to keep Miami in it, combining for 15 in the quarter.

Wade stayed hot in the third, scoring 11 more -- highlighted by one stretch where he managed to get a rebound as he was stretched out on the court after a collision, and then a drive not long afterward where he got knocked down again.