The Eagles, who have not won an Atlantic Coast Conference game this season, led the whole way until Theo Pinson hit two free throws with under 4 minutes remaining. After BC retook the lead, Marcus Paige hit a 3-pointer to make it 62-60.
The Tar Heels (20-4, 9-2) snapped a two-game losing streak.
Dennis Clifford had 14 points and 13 rebounds for BC (7-17, 0-11).
BC's Matt Milon hit a 3-pointer with 5.6 seconds left to make it a one-point game. But after Paige made two free throws, Eli Carter's 3-point attempt from halfcourt at the buzzer bounced harmlessly off the backboard.
Carter scored 26 points.
Carolina spokesman Steve Kirschner said Williams, 65, who has suffered from vertigo in the past, felt dizzy and returned to the locker room but was OK. Assistant Steve Robinson took over the coaching, and the Tar Heels eventually came around after falling behind by nine points in the first half.
Clifford had six rebounds in the first 6 minutes to help BC open a 13-4 lead. The 7-foot senior, who has had only one double-double in his career, finished the first half with nine boards and eight points, then opened the second half with a dunk that he celebrated by flexing his arm at the BC bench.
Clifford added another dunk with 7:33 left to make it 56-49. This time, he threw it down with both hands, then flexed both arms as he ran back on defense.
But BC went cold, failing to score for almost 4 minutes while the Tar Heels ran off eight straight points to take their first lead of the game.
Clifford missed the front end of a 1-and-1, then fouled Theo Pinson going for a rebound. Pinson made both free throws with 3:55 left to put Carolina ahead 57-56 with 3:55 left.
Carter made one of two free throws to tie it and then, after Jackson hit a jumper in the lane, Carter made a 3-pointer to give the Eagles a 60-59 lead. It was their first basket in 5:24.
But Paige hit a 3 with 1:47 left, and after BC couldn't get a shot off Jackson made a short jumper from the side to give Carolina a four-point lead. It was still four points when Milon made a 3 with 5.6 seconds to play to make it 66-65.
But Paige made his free throws, then Carter was forced to take an off-balance shot at the buzzer that wasn't close.
North Carolina: The Tar Heels are coming off their longest losing streak of the season: two games. They haven't lost three straight conference games since they started the 2013-14 season by losing three in a row.
North Carolina: Hosts Pittsburgh on Sunday.