The Knicks lost their fourth straight after seeing a fourth-quarter comeback come up just short.
Tyson Chandler hit a free throw with 21 seconds left to bring the Knicks within one, but Gay then went 2-of-2 from the line and connected on another foul shot with 7 seconds left to give the Raptors a four-point cushion.
Carmelo Anthony brought New York within two on a layup with 3 seconds left, but the Knicks could not come up with another possession.
Toronto took a nine-point lead into the fourth quarter on its way to its sixth win in seven games. The Raptors' only loss in that stretch came against Memphis on Wednesday.
DeMar DeRozan added 18 points for Toronto and Kyle Lowry had 15. Anthony led New York with 32 points and J.R. Smith had 19.