Williams' 3-pointer with three minutes left gave New Mexico a 61-60 lead and his layup with under a minute left gave the Lobos the lead for good, 65-63.
Rashad Muhammad's 3-pointer with 1:30 left pulled San Jose State even, 63-63, but the Spartans did not score until Jalen James' layup with one second left.
Williams finished with 19 points, six rebounds, seven assists and three steals for New Mexico (12-3, 3-0 Mountain West). Cameron Bairstow and Deshawn Delaney added 15 and 12 points, respectively.
The Lobos shot just 15 of 27 from the line, but the Spartans attempted just nine free throws.
Jaleel Williams had 24 points and eight rebounds to lead San Jose State (6-10, 0-4), with Muhammad adding 16 points off the bench.