With less than 30 seconds left DeRozan made a three-point play on a layup and a free throw to lift the hosts to a seven-point lead in a game that had seen 27 lead changes and 20 ties.
Norman Powell scored 19 points and Kyle Lowry added 16 for the Raptors, who have won two straight.
Carmelo Anthony led New York with 31 points while Derrick Rose and Kristaps Porzingis chipped in 21 apiece.
Joakim Noah added four points and 18 rebounds for the Knicks, who were trying to bounce back from a 28-point defeat on Friday in Boston — where six technical fouls handed out to New York players included two to Anthony that saw him ejected from the game.
Know more about Sport360 Application