BRISTOL, Va. — It was perhaps the longest 90 seconds of the basketball season for Castlewood and Galax.

The Blue Devils (23-4) outlasted the Maroon Tide (17-8) on Saturday 46-44 in the VHSL Group A Division 1 quarterfinals to reach the Final Four for the first time.

The teams were never separated by more than four points from tipoff to final buzzer. There were 17 lead changes and 10 ties.

Finally, it was time for one to blink in the staredown.

After Patrick Anderson’s tip-in gave Galax a 41-39 lead, it was Castlewood’s cue to nail down a berth in next Thursday’s semifinals against Madison County at the Siegel Center in Richmond.

Justin Smith, a 6-foot-3 senior guard, ripped through his fourth 3-point goal of the game for a 42-41 lead with 1:30 left to play.

The remaining time on the clock was seemingly eternal as coaches engaged in a battle of wits.

Thirty-two seconds later, Zach Bush came off the board with a rebound contested by three Galax players and was fouled. He converted two free throws for a 44-41 edge, but the game was far from being over.

Castlewood mentor Wayne Rasnick sent in 5-8 senior Ethan Collins to guard against a perimeter shot. He sprang up to block a 3-point attempt and Ruben Rasnick, a 6-4 senior, recovered the ball.

“People can’t believe how well he can jump,’’ Coach Rasnick said. “At this point of the year we’re in certain situations and that was the time to get him in there.’’

Rasnick, son of the coach, cashed in one of his two freebies with 29 seconds to go. Castlewood’s 45-41 lead appeared to be secure.

But lo and behold, Galax coach Verl Brown put Austin Pack in the game specifically to fire up a 3-pointer and he connected from 28 feet, cutting the margin to 45-44 with nine seconds showing.

Bush was immediately fouled, and he scored the final point with seven seconds left. Still, Galax wasn’t throwing in the towel. After each team called a timeout, Justin Hash uncorked a 3-point shot that climbed the rim. Teammate Deion George tipped the ball and it spun out of the cylinder as time elapsed.

Bush, the Blue Devils’ inspirational leader in postseason play, led the winners with 17 points. Smith, who was 5-of-10 from the floor, scored 14 and Rasnick added 12.

“Bush isn’t going to be undersized by anybody,’’ Rasnick, the coach, said. “He isn’t afraid of anything. I believe if we asked him to run through a wall he would.’’

Castlewood was extremely efficient on offense. Its precise ball movement around the horn kept Galax on its heels.

Defensively, the Cumberland District champions trapped on the wings to disrupt the Tide’s attack.

“We played good team defense,’’ Coach Rasnick said. “That’s what got us here. We intended to ‘D’ somebody up in the final minutes.

“We’re really proud of all 15 kids on this team for what they do both on and off the floor. They’re students first and pretty darned good athletes.’’

Brown was gracious in defeat.

“Castlewood has a well-disciplined team that knows how to find a way to win,’’ he said. “You could see the leadership take over. Our effort was the best we had all year.’’