Alexey Shved tallied 15 points with five assists off the bench for New York, winners in two straight following an eight-game slide.
The Knicks were playing with a heavy heart after learning that fan favorite Anthony Mason, who played in New York from 1991 until 1996, died at the age of 48. The 1995 Sixth Man of the Year suffered a massive heart attack earlier in the month and had been hospitalized since then.
Louis Williams scored 22 points to lead the Raptors, who have lost a season- high five straight games. Jonas Valanciunas added 16 and eight rebounds in defeat.
Toronto was without All-Star point guard Kyle Lowry, who was given the night off to rest. He is considered day-to-day.
The Knicks limited Toronto to 15 points on 6-of-19 in the first quarter. Shved hit a 3 early in the second, giving New York its biggest lead at 25-15.
Greivis Vasquez scored on the front and back end of a 9-0 run later in the second to put the Raptors in front. The spread was within five either way from there until a 3-pointer by Shved sparked a 14-2 run early in the fourth.
Lou Amundson scored seven points during the flurry, which forced a pair of Toronto timeouts. His hook shot over James Johnson at 5:50 made it 94-81.
The Raptors used a 17-6 run after that to pull back within two. Patrick Patterson's putback with 33 seconds left cut New York's deficit to 100-98.
But out of a timeout, Shved kicked to Langston Galloway, who was pure with a 3-ball from the right wing to restore a two-possession advantage. DeMar DeRozan missed a short pull-up at the other end, and Hardaway secured the rebound.
DeRozan shot 3-for-15 from the floor ... There were nine ties and nine lead changes ... Vasquez had 14 points and six assists for Toronto.