CHAPEL HILL, N.C. — Virginia limped in with losses in three of its last four games. Thanks to a huge night from their quarterback and a couple of timely stops, the Cavaliers are now in control of their division.

Bryce Perkins amassed 490 total yards and accounted for five touchdowns to help Virginia beat North Carolina 38-31 on Saturday night.

Perkins threw three touchdown passes and ran for 112 yards and two scores as the Cavaliers (6-3, 4-2 Atlantic Coast Conference) took over sole possession of first place in the ACC's Coastal Division. They also became bowl-eligible for the third consecutive season.

"We're not done yet," Perkins said. "We've got to keep going to complete our goals."

Perkins gave Virginia the lead for good on the second play of the second half, scrambling through North Carolina's defense for a career-long 65-yard touchdown.

The play was part of an avalanche of points for the Cavaliers, who trailed 17-10 late in the second quarter before scoring touchdowns on four consecutive possessions.

The Tar Heels twice had a chance to tie the game late in the fourth quarter. Their best opportunity came from Virginia's 6-yard line with five minutes remaining, when Sam Howell's fourth-down pass to Beau Corrales was incomplete.

"We knew we had to get a stop," Virginia defensive end Eli Hanback said. "There was no other option."

Howell was 15 of 29 for 353 yards and four touchdowns for North Carolina (4-5, 3-3).

Dyami Brown had six catches for a career-high 202 yards and three touchdowns for the Tar Heels.

"Physically, psychologically and emotionally, these guys have played their guts out every week," North Carolina coach Mack Brown said. "Every game has come down to the end. It's been unbelievable."