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.
Boston schools pull out free condoms over wrapping complaints
Ray Liotta sues skin care company over use of likeness