Kyle Guy finished with 23 points and seven rebounds to help lead Virginia to a 64-58 win over Virginia Tech in Blacksburg. (Michael Thomas Shroyer/USA Today Sports)

There wasn’t a defender anywhere in sight when Virginia’s Mamadi Diakite dribbled toward the basket, leaped with both hands on the ball and attempted a dunk to punctuate a victory for the third-ranked Cavaliers against No. 20 Virginia Tech.

But the forward missed badly — the ball clanged off the rim and landed in the arms of Hokies guard Ahmed Hill with 21 seconds to play.

The embarrassing moment was about all that went wrong for the Cavaliers down the stretch of a 64-58 win in the Commonwealth Clash on Monday night at boisterous Cassell Coliseum.

“I told him, ‘No more missed dunks,’” Cavaliers Coach Tony Bennett said after Virginia (23-2, 11-2) won its third in a row to move into second place by itself in the ACC, a half-game behind top-ranked Duke.

The blunder couldn’t spoil an otherwise positive night for the Cavaliers, who got 23 points and seven rebounds from Kyle Guy, who went 6 for 13 from three-point range and had a rare putback dunk in the first half. Ty Jerome added 16 points and six assists, none more significant than his pass to Braxton Key for a three-pointer yielding a 56-43 lead with 5:51 to go.

Virginia Tech (20-6, 9-5) pulled back to within 61-54 with 1:25 left on Hill’s three-point play, but Key made his second and final three-pointer 28 seconds later to help secure a regular season series sweep for Virginia. The Cavaliers won despite committing 13 turnovers, but they had none over the final 5:11.

It was the fourth time in five games Virginia has committed double-digit turnovers. In this instance they led to 13 points for the Hokies, who shot a season-worst 3 for 28 (10.7 percent) from beyond the arc in dropping to seventh in the conference standings.

“All credit for sure to them,” Hokies Coach Buzz Williams said of the Cavaliers, who are ranked first nationally in three-point field goal shooting defense. “They were superb on both ends of the floor, and they’re the reason why we missed those shots.”

Kerry Blackshear Jr. led Virginia Tech with 23 points and a game-high 13 rebounds. Hill chipped in 16 points for the depleted Hokies, who did not have senior point guard Justin Robinson for the sixth consecutive game.

The program’s career leader in assists is out indefinitely, according to Williams, with a left leg ailment.

In front of an announced crowd of 9,275 that included legendary former Hokies football coach Frank Beamer, Virginia Tech stayed close well into the second half. An 11-3 push capped by De’Andre Hunter’s putback provided Virginia with its first double-digit lead of the game at 48-38 with 11:08 to play.

The run included a three-pointer from Guy and a two-handed dunk by Diakite, leading to a timeout from Williams four seconds later. Out of the stoppage, though, Virginia Tech committed a shot-clock violation.

The Hokies had eight turnovers but only three in the second half.

“They play so hard,” Guy said of the Hokies. “Very much respect for them for playing as hard as they did, and they’re well coached. Like I said, we had a couple mental lapses where we probably could have pulled away, but hat’s off to them.”

The rematch between the contentious in-state rivals separated by roughly 150 miles came a little more than 48 hours after both schools survived spotty performances against opponents in the bottom rung of the conference.

The Cavaliers didn’t secure their 60-54 victory over 11th-place Notre Dame on Saturday until the closing seconds when the Fighting Irish missed a three-pointer that would have closed the margin to one. Later Saturday afternoon, Virginia Tech was unable to pull away from last-place Pittsburgh until the final minutes of a 70-64 win.

The Hokies entered Monday first in the ACC and third in the country in three-point shooting percentage (41.8) but faced a tall order trying to gain clean looks from beyond the arc against the Cavaliers, who won the first game between the teams this season, 81-59, at John Paul Jones Arena.

Virginia Tech shot 2 for 13 from beyond the arc in the first half but went into halftime with momentum and trailing only 32-29 thanks to Isaiah Wilkins’s steal in the last seconds that led to his layup at the buzzer.

Virginia had led by as many as seven points in the first half, an advantage the Cavaliers earned after Jerome completed a four-point play when he made a shot from beyond the arc while drawing a foul.

But the Hokies came storming back behind Blackshear, who scored three straight baskets, two of which were dunks. His second field goal in that stretch came moments after he stole the ball from Jerome near midcourt for one of Virginia’s eight first-half turnovers.

“I thought we were better in the second half with ball security,” Bennett said. “But again, that’s the stuff that we’ve got to keep being better at. I liked our second half. Wasn’t perfect, but I liked how they responded. I did not like our first half at all.”