Williams had missed a three-pointer seconds earlier but the Jazz corralled an offensive rebound and he got another chance.
Williams ran down the clock, pulled up a few feet behind the three-point line and sank the basket to end the game and send the crowd into a frenzy.
"We all knew (Williams) was going to take it after he missed that last one," Jazz reserve Gordon Hayward told reporters after scoring 19 in the win.
"We knew he was going to step up and shoot it with confidence. We had faith in him, and he knocked it down."
It was Utah's (13-10) fourth straight win and snapped a five-game win streak for the Spurs (18-5).
Utah's Paul Millsap finished with 24 points and 12 rebounds while Al Jefferson chipped in with 21.
The Jazz had trailed by eight with a little more than four minutes remaining but battled back to tie the game and snatch victory with the final shot.
Tony Parker and Tim Duncan had 22 points apiece for San Antonio with Duncan also adding a season-high 21 rebounds.
Utah outscored the Spurs 31-16 in the second quarter to grab a nine-point lead at halftime but the visitors tied it by the end of the third.
During the fourth-quarter battle, Hayward made a pair of three-pointers down the stretch to keep the Jazz close before they ended the game with a triumphant 11-2 spurt.
San Antonio's Danny Green was defending the final play and took a costly step back as Williams drained the shot.
"That's a huge defensive error," said Spurs coach Gregg Popovich. "What do you think a guy is going to do with two seconds left on the clock? You make him drive. You don't step back on Mo Williams."