Gay's score-tying basket with 20.8 seconds remaining in regulation sent the game into overtime and Thomas secured the victory with a score late in the extra time for Kings, who had erased a 12-point second-half deficit.
DeMarcus Cousins provided 19 points and 14 rebounds, but missed the overtime after sustaining a strained left hip flexor.
Carmelo Anthony pumped in 36 points and grabbed 11 rebounds for the Knicks, losers of four in five.
Amar'e Stoudemire netted 20 points and Tyson Chandler totaled 17 with 11 rebounds.
Teacher apologizes for showing sexual image of herself in class
Interpol investigating stolen passports on missing flight