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.
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'