De’Andre Hunter finished with 20 points in Virginia’s 69-61 victory at North Carolina. (Bob Donnan/USA Today Sports)

The No. 4 Virginia men’s basketball team needed to regroup quickly for its visit to No. 8 North Carolina on Monday night, which came only 48 hours after absorbing its ­second loss of the season.

The Cavaliers instead nearly unraveled in the second half before Kyle Guy came to the rescue, sinking a pair of three-pointers in the final two minutes to secure a 69-61 victory.

Guy finished with 20 points, going 5 for 9 from beyond the arc, and point guard Ty Jerome added 15 points and 11 assists with just two turnovers despite back discomfort to help Virginia (21-2, 9-2 ACC) avoid consecutive losses for the first time since 2016-17.

The Cavaliers also got 20 points from De’Andre Hunter and shot 53.3 percent from the field, including making 11 of 20 tries from three-point range, to win for the second time in their past 11 trips to Smith Center in front of a crowd that included Tar Heels legend Michael Jordan.

“Obviously we made some big threes. Kyle hit some big shots,” Virginia Coach Tony Bennett said.

“It was a game of ebb and flow for sure, just challenging, hang in there, get a stop. I thought we had some tough stretches, and Carolina did some good things, of course. But when you have a guy like Kyle, guys just made some plays and were sound enough.”

Guy’s final three-pointer with 1:10 to play produced a 67-61 lead and gave him 20 points for the first time in 10 games. About two minutes earlier, Jay Huff’s layup had given Virginia a 61-59 lead, putting the Cavaliers ahead to stay in a game with six lead changes and four ties. Just before Huff’s go-ahead basket, North Carolina guard Coby White made a three-point heave from near midcourt with 3:29 to play, but officials ruled he released the ball after the shot clock had expired.

The Cavaliers limited North Carolina (19-5, 9-2) to 35.4 percent shooting for the game and did not commit a turnover in the final 12:23 after having 10 to that point. Turnovers had been a significant concern for Virginia over the previous three games, during which it committed 44.

During a timeout with 11:32 to play, Bennett got so heated toward his players about the turnovers that he said he “almost blew out a couple veins in my neck.”

Still, Virginia managed to withstand an uprising from the Tar Heels in the second half by countering with seven points in a row, including three-pointers from Guy and Jerome, to tie the score at 55 with 6:09 to play.

Moments before Jerome’s tying three-pointer, Tar Heels starting guard Cam Johnson landed on the court, holding his leg. The team’s second-leading scorer this season left the game briefly but reentered in the final minutes, finishing with 16 points and seven rebounds.

White led the Tar Heels with 17 points.

The Cavaliers had led 40-32 before North Carolina stormed back thanks to a 17-3 run that began with White’s driving layup followed by Kenny Williams’s three-pointer and a dunk by Garrison Brooks.

Hunter answered for Virginia with a three-pointer, but Johnson scored five in a row, including a layup for a 44-43 lead with 14:17 left. It was the first lead for the Tar Heels since they were up 11-8 early in the first half, and they grew the margin to seven multiple times before Virginia rallied.

“I feel like we had a great chance to win,” Brooks said. “We just didn’t seize the opportunity.”

The only regular season meeting between last year’s ACC tournament finalists came after Virginia lost to first-place Duke, 81-71, on Saturday night in ­Charlottesville.

The turnaround didn’t provide the ailing Cavaliers much time to prepare for surging North Carolina.

“There’s no excuses,” Jerome said. “I told the team before the game: ‘I don’t care if we played Duke Saturday. I don’t care if we’re on the road today. Every game we come out and we expect to win, no matter where we are, no matter who we’re playing against.’ So it was really good to get this one.”

Among the primary concerns health-wise for Virginia had been the status of starting forward Mamadi Diakite. The junior collided headfirst with Hunter in the first half against Duke and did not reenter while being examined for concussion symptoms.

Diakite came off the bench against North Carolina and scored on a jump hook over Johnson to cap a 10-0 run early in the first half that gave the Cavaliers a seven-point lead.

Jerome continues to play with the sore back that forced him to sit out against Miami on Feb. 2, marking the first game the junior missed in his career. Jerome initially tweaked his back against N.C. State on Jan. 29.

Jerome scored the final basket of the first half Monday for Virginia to close a run of five straight points, providing the Cavaliers a 36-29 lead heading to halftime.

The first half also included North Carolina freshman forward Nassir Little landing awkwardly on his right leg. The Tar Heels’ fourth-leading scorer and top reserve remained on the court briefly, clutching his right ankle and calf, before getting up and walking gingerly to the locker room. He did not play the rest of the game as Virginia bounced back with a victory.

“Our guys knew what we had to do, and they responded,” ­Bennett said. “It wasn’t perfect, but I told them this isn’t about winning or losing. I said, ‘This is an important game to get back to what we need to do.’ They were ready, and they were locked in.”