After beating Maryland in overtime, Virginia earned the No. 4 seed and a first-round bye in the ACC tournament. The Terrapins are the No. 7 seed and face Wake Forest in the first round. (John McDonnell/The Washington Post)

Had any player or coach on Maryland or Virginia wandered down to the opposing bench at John Paul Jones Arena on Sunday night, he would have been met with a mirror image.

All season, these two teams have followed encouraging wins with disappointing losses, and shown signs of progress only to respond with confounding lapses. Neither has found a reliable point guard and each owned a spot firmly on the NCAA tournament bubble entering the final ACC regular season game of the year.

None of those inconsistencies was erased in Virginia’s improbable 61-58 overtime victory.

But following a disastrous first half in which the Cavaliers fell behind by 17 points, Coach Tony Bennett’s team exorcised some late-game demons and authored a comeback that could very well be their saving grace come Selection Sunday.

Freshman center Mike Tobey (13 points) tallied the two decisive field goals. He scored on a lay-in with 5.6 seconds remaining in regulation to send the game to overtime and a tip-in that gave Virginia the lead for good with 1 minute 47 seconds left in the extra period. Tobey later said his winning basket actually went off the fingertips of Maryland center Alex Len.

The Terrapins had three chances to tie or take the lead in the final minute of overtime. Instead, they produced two turnovers and a missed three-pointer by guard Dez Wells as the final buzzer sounded.

“We were very fortunate to win. I’m not a dummy on that one,” Virginia Coach Tony Bennett said.

Virginia’s 17th straight victory at home also was its first since it upset No. 3 Duke on Feb. 28. The Cavaliers earned the No. 4 seed and a first-round bye in this week’s ACC tournament. They will face either No. 5 seed North Carolina State or No. 12 seed Virginia Tech in Friday’s quarterfinal round.

Maryland, meanwhile, fell to 2-7 on the road in ACC play; as the No. 7 seed, it will face No. 10 seed Wake Forest on Thursday. The Terrapins, though, will enter the postseason on the heels of a collapse that saw them shoot just 25 percent from the field in the second half and overtime.

Sophomore Nick Faust led Maryland with 15 points. However, 13 came before halftime when the Terrapins built a 17-point lead courtesy of a 19-2 run. Maryland’s shot selection deteriorated as the game wore on, and after initially answering Virginia’s charge with three-pointers by guards Logan Aronhalt and Seth Allen, it struggled to convert against the Cavaliers’ ACC-best defense.

“We did get to the rim. We didn’t finish around the rim,” Coach Mark Turgeon said. “We had a chance for second-chance buckets and couldn’t do it. We missed a lot of shots. Even though we shot 32 percent and only scored 58 points in 45 minutes, I felt like we had control offensively. I never felt like we were being dictated by them, which is hard to do in this building.”

If Virginia was hoping to make a statement to the NCAA tournament committee after two straight losses, it sure didn’t play like it early on. After torching the Terrapins in College Park a month ago, Virginia appeared listless and scored just 19 points before halftime as Maryland used a diamond-and-one press and a 1-3-1 zone extensively for the first time this season.

“I’ve never been nervous before,” said Akil Mitchell, who led the Cavaliers with 17 points and 10 rebounds. “I don’t know if it was the pressure of the NCAA tournament, but I felt it and a lot of other guys felt it, too.”

But the Cavaliers received a jolt from freshman Justin Anderson, who hit a three-pointer just before halftime and finished with five blocks, including one on Terrapins guard Pe’Shon Howard during the final possession of regulation.

The former Maryland commit also ignited a 10-3 Virginia run early in the second half following a technical foul called on Howard.

Virginia still had to overcome a third straight poor shooting performance by leading scorer Joe Harris. The junior finished with 15 points on 4-of-18 shooting, and went more than 27 minutes between field goals. But he said he kept thinking “the next one was gonna go in,” a premonition that came true when he nailed a three-pointer with 1:35 remaining in regulation to tie the score at 52.

Wells answered with a runner in the lane over Anderson to put Maryland back on top by two points with 23 seconds remaining. But after Bennett used his final timeout — something he didn’t do in the final seconds of Virginia’s last-second losses at Boston College and Florida State — Anderson found Tobey underneath the basket directly off an inbounds pass for the dramatic game-tying field goal.

As it turned out, Tobey was the third option on the play. When the Cavaliers had run it in the past, Anderson never inbounded the ball. Given the circumstances, though, the details mattered little.

“This was a great, gutsy win for us,” Tobey said, a relieved smile on his face.