The Hokies climbed to 10-1 for the season and are 6-1 in the ACC's Coastal Division. If Virginia defeats Florida State Saturday, the Virginia Tech-Virginia season finale next week will determine the division champion and a berth in the conference title game.
Virginia Tech took a 24-7 lead into the fourth quarter with Thomas throwing for two scores and running for another.
North Carolina then scored in the final period on a 5-yard pass from Bryn Renner to Erik Highsmith and a 1-yard run by Ryan Houston.
Houston's score came with 2:32 to play, but the Hokies recovered the ensuing onside kick and eventually killed off all but 2 seconds off the clock.
Thomas threw an 11-yard scoring pass to Chris Drager that tied the score in the second quarter.
Cody Journell's 22-yard field goal in the second period put the Hokies in front for good, after which Thomas ran 23 yards for a touchdown and hit D.J. Coles with a 4-yard scoring pass.
Thomas was 19-of-32 for 195 yards. North Carolina fell to 6-5 and is 2-5 in league play.