Virginia (4-4, 2-2), which had kept the explosive Williams and North Carolina scoreless to that point in the second half, then was surprised when the Tar Heels tried, and recovered, an onside kick.
North Carolina drove to the Virginia 20, where it faced a fourth-and-1, and a whistle for too many men on the field against the defense gave UNC a first down, and Williams and Co. then ran out the clock. It is the fifth consecutive victory in the series for North Carolina.
Until the closing minutes, Virginia had mostly kept the red-hot Williams and Tar Heels at bay, save for three quick drives in the first half, all ending in big plays. Williams came in averaging 449 yards of offense in his last two games, but finished with 308 as the Cavaliers outgained North Carolina 443-374.
But for all the yardage, Virginia managed just one field goal in the second half, and when Greyson Lambert threw a dump pass into the arms of 280-pound defensive tackle Nazair Jones, and he returned it 20 yards to the Cavaliers' 38, it proved to be one request too many of the Cavaliers' defense.
The decisive touchdown came after Eli Harold sacked Williams for minus 10 yards on second-and-5 from the 6, and Williams' helmet came off, meaning he had to sit out the next play per NCAA rules.
In trotted Trubisky for the third-and-15 play, and Thorpe made it easy.
Lambert, who returned to the lineup after missing three games with an ankle injury, had been sharp until that play, but the Cavaliers' last two scoring drives stalled and resulted in field goals.
He had two big completions - 24 yards to Canaan Severin to convert a third-and-10 from the Virginia 28, and a 42-yarder to Darius Jennings - as Virginia went ahead 21-14. Jennings' catch brought the ball to the 5, and Lambert hit Kevin Parks for a 2-yard reception two plays later to give Virginia the lead.
It lasted four plays.
Williams hit Jack Tabb for 22-yards on a third-and-8 play from his 15, then found Hollins behind safety Anthony Harris for a 63-yard scoring play. Williams released the ball as linebacker Henry Coley leveled him and had to be helped up, but Hollins made a gorgeous fingertip catch on the play.
The Cavaliers led 24-21 at halftime after Ian Frye's 31-yard field goal with 28 seconds left.
Williams did little on the Tar Heels first two series, then did plenty, and fast.
Trailing 14-0, he kept the ball on a read option and went 48 yards untouched for the touchdown, capping a four-play, 75-yard drive that took 45 seconds. After Virginia's first three-and-out, the Tar Heels needed just two plays, the second Williams' 52-yard scoring pass to Mack Hollins, to make it 14-all.
On the play, Hollins beat cornerback Maurice Canady and dodged a tackle by safety Anthony Harris.
The Tar Heels started their next two drives in Virginia territory, but Nick Weiler missed a 39-yard field goal try on the first, and David Dean sacked Williams on fourth down to end the second one.
The Cavaliers made North Carolina's defense look like the 124th-worst on their first two possessions, driving 66 yards in nine plays to Lambert's 31-yard scoring pass to Canaan Severin, and then 90 yards in nine plays to Kevin Parks' 2-yard touchdown run. Lambert had completions of 22 yards to Miles Gooch on third-and-8 and then caught a 23-yard pass from Gooch two plays later on the second drive.
The Cavaliers, at that point, had a 141-5 yardage advantage, but that changed quickly.