They trailed by 14 points with less than 5 minutes left in the third quarter before scoring on four straight possessions to take a four-point lead, then made a late defensive stand to earn their first 2-0 start under third-year coach Larry Fedora.
Quinn Kaehler threw for a career-high 341 yards with a touchdown, then led the Aztecs (1-1) to a first-and-goal from the North Carolina 3 in the final minute.
He threw a quick pass in the end zone to Lloyd Mills, but Scott jumped in front of it for the game-sealing interception.
Kaehler finished with a 56-yard touchdown pass to Eric Judge, and Donnel Pumphrey rushed for 100 yards with scoring runs of 12 and 3 yards for San Diego State, which led 21-7 late in the third quarter before Williams and the North Carolina offense finally started clicking.
Williams threw TDs covering 91 yards to Mack Hollins - the third-longest TD pass in school history - and 11 yards to Quinshad Davis. Brian Walker picked off two passes, returning the first one 100 yards for an early touchdown.
After Danny Hageman's second field goal of the fourth quarter, a 40-yarder with 10:30 to play, made it 27-21, the Tar Heels went 80 yards in eight plays and reclaimed the lead for good. Hood's first career touchdown run made it 28-27 - their first lead since early in the second quarter.
Walker then picked off Kaehler's across-the-body pass and took it 26 yards to the San Diego State 14 to set up Nick Welier's 23-yard field goal with 4 minutes left that ended the scoring.
The Aztecs certainly appeared on their way to a rare Eastern victory after Pumphrey put them up by two touchdowns with his scoring run on the opening drive of the second half.
That turned out to be the wake-up call the Tar Heels needed, with Williams throwing for TDs on consecutive possessions to get North Carolina back in the game.
The first came on a short fade pattern in the end zone to Davis.
The second was spectacular.
One play after San Diego State pushed its lead back into double figures, the Tar Heels went deep: Hollins slipped behind cornerback J.J. Whittaker near midfield and pulled in Williams' pass in stride on his way to the longest pass play by a Tar Heel in the history of Kenan Stadium.
But it wasn't even the longest play of the day.
That belonged to Walker, who picked off Kaehler's overthrown pass about a yard deep in the end zone and took off down the right side for the game's first touchdown.