The Tar Heels (10-1, 7-0 ACC, No. 17 CFP) won their 10th in a row and clinched the Coastal Division title, and did so despite blowing a 14-point lead in the final three minutes of regulation.
Virginia Tech (5-6, 3-4) tied the game on Michael Brewer's 4-yard, fourth-down pass to Isaiah Ford with 1:07 remaining, but the Hokies had to settle for a field goal to begin the overtime.
Williams then hit Ryan Switzer for 18 yards on the Tar Heels' first play, and after two runs and a false start penalty put them at the 5, Williams hit Davis, who beat Terrell Edmunds in the right corner of the end zone.
North Carolina will play No. 1 Clemson in the ACC championship game on Dec. 5.
Elijah Hood turned two Virginia Tech turnovers into fourth quarter touchdowns as the Tar Heels opened a 24-10 lead, sending some fans heading for the exits when Brewer was intercepted a second time.
The Hokies, though, used a takeaway of their own to pull within 24-17 with 2:54 left on Brewer's 8-yard scoring pass to Bucky Hodges, and then got Williams fumble on a sack by Luther Maddy.
Brewer then hit Isaiah Ford for 36 yards to the Tar Heels' 12, and after two runs and an incomplete pass gave them a fourth-and-2 at the North Carolina 4, Brewer hit a sliding Ford for the tying touchdown
The Hokies tried to give Beamer a win in the final home game of his 29-year career. They shut down the ACC's most potent offense for three quarters, but hurt themselves with late turnovers.
Virginia Tech needs a win at Virginia next Saturday to give Beamer a 23rd consecutive bowl appearance.
The Tar Heels came in having scored 125 points in their last two games. They were second in the league with an average of 495 yards of offense, but managed just 193 in three quarters.
For a time, it looked like Bud Foster's defense would give the Hokies a chance.
After falling behind 10-3, missing a field goal and squandering a good scoring opportunity after forcing the Tar Heels' first turnover in four games, the Hokies put together their best drive of the day.
Brewer hit Cam Phillips for 10 yards on a third-and-8 from midfield, Rogers had an 18-yard run and Brewer carried it the last three yards on a third-and-goal draw play to pull Virginia Tech even.