Stoudemire grabbed 12 rebounds and Lin contributed 10 assists for the Knicks, who recorded their fourth consecutive win under interim Coach Mike Woodson.
Carmelo Anthony supplied 17 points, eight boards, five assists and three steals for the winners.
The Raptors got 17 points from DeMar DeRozan and Jose Calderon, who returned from a sprained ankle, added 11 points and nine assists.
Toronto finished a five-game road trip with a 2-3 mark.
Iranian woman stops the execution of son's killer
Rosie O'Donnell unveils nearly 50-pound weight loss