A great coach once said, “What counts in sports is not the victory, but the magnificence of the struggle.” By that standard, the boys’ basketball team’s magnificent but ultimately heartbreaking 83-76 overtime loss to Wareham in the second round of the Division 3 south region state tournament on Wednesday must be considered a success.

But another famous coach once said after a particularly tough defeat, “We didn’t lose the game; we just ran out of time,” and this logic could also be applied to the contest, in which Vineyarders held as much as a 7-point lead and hit a dramatic last-second shot to send the game into overtime.

Although the Vikings ultimately prevailed thanks to a few key rebounds in the final period and some questionable calls from referees, this was a game determined as much by luck and timing as by quality of play.

“It was almost like a football game in that the logic of whoever had the ball last was going to win the game,” said exasperated coach Mike Joyce after the loss. “It’s not like we were outplayed or made any crucial mistakes, it’s more like the game happened to end when they were leading.”

He added: “This game could have easily gone to a second or third overtime . . . these two teams are that evenly matched.”

Although coming in as the 14th seed against the third-seeded Vikings, and despite playing in front of a fanatical (and at times hostile) crowd, the Vineyarders entered the contest with a lot of confidence. Earlier in the week, they defeated a talented Westwood Wolverines team by a final of 81-65.

Jwann Johnson attempts shot in Monday’s game. — Jaxon White

In that win, the Vineyarders built a 17-point lead early before the 19th-seeded Wolverines scratched back to pull within 6 in the fourth quarter. Mark Reppert had a game-high 24 points to help seal the win, while Nick Viera scored 15 points, Jwann Johnson had 14 points and Bubba Brown had 10 points.

Reserve Cody Brewer started the game against the Wolverines in place of Nico Cuba, who was forced to travel to his native Uruguay to secure a student visa for college. Brewer was more than up to the task, scoring 11 points and pulling down nine rebounds in Cuba’s absence.

Brewer would also play a huge part in Wednesday’s game against Wareham.

Several hundred Vineyard fans — some sporting the team colors of purple and white — traveled with the team and packed themselves into the tiny tinderbox of the Wareham high school gymnasium. The Vikings crowd was rabid from the start, and unfortunately not always well-behaved. Several times during the game the crowd joined together for chants and taunts, and at one point two fans of opposing teams engaged in an impromptu dance contest on the court floor.

Despite the antagonistic environment, the Vineyarders were cool and collected from the start, building a 16-11 lead in the first quarter and a 27-23 lead in the second quarter. The Vineyarders dominated the higher-seeded Vikings early on and proved to be more dynamic. Johnson and Viera hit shots from the wings while Mark Reppert continually drove the lane and attacked the basket.

But the one thing working for the Vikings was working well, as sophomore center Ryan Pina continually reeled in passes in the paint and converted seemingly every time he touched the ball.

In the two previous games against the Vineyarders, the 6-foot, 3-inch Pina was essentially a non-factor, scoring only five points each time. But Pina dominated on Wednesday, finishing with 26 points and 11 rebounds.

The Vikings’ game plan from the start was to get the ball to Pina in the paint and to neutralize the Vineyarders’ big man, Bubba Brown. The plan worked to perfection as Brown was called for two fouls in the first few minutes of the game, forcing coach Joyce to sit him for much of the first half.

Sophomore Pat Hart, a bench player for most of the season, was called into fill Brown’s sizable shoes, and the underclassman was better then anyone could have expected, scoring 16 points and corralling 11 rebounds while helping to cool off the hot hand of Pina for much of the first half.

“Pat [Hart] had the game of his young career; he was just brilliant,” coach Joyce said. “We brought him into a tough spot and he performed well beyond our wildest expectations. He was one of the reasons we stayed close all game.”

The two teams exchanged leads through the first half, and the Vineyarders held a slight 35-33 advantage at the half. The Vikings scored twice early in the third quarter to take their second lead of the game, but a pair of jumpers by Viera and two baskets in the paint by Brown gave the Vineyarders a 48-41 advantage midway through the period.

It would be the Vineyarders’ largest lead of the second half and also a low point for the Vikings, who looked tired and shell-shocked as the visitors were beating them both from inside and outside.

But Wareham coach Kevin Brogioli did not call a time-out. Instead, he let his team fight it out, and they responded when guard Aaron Frye hit a 3-pointer followed by a 2-point basket by guard Pat Murphy to pull within a point.

The game remained close until early in the fourth quarter when the ever-clutch Viera drained a 3-pointer which both deflated the home crowd and gave the Vineyarders a 59-54 lead. After the Vikings sank a free throw on their next possession, the score remained static at 59-55 for the next three minutes as both teams suddenly went cold from the field.

For coach Joyce, this was the most stressful stretch of the game.

“I kept looking up and it seemed like the score was frozen at 59-55 forever,” the coach said. “If we were able to get a few more baskets during this stretch we might have won. But they buckled down [on defense] and shut us down.”

The Vikings finally broke through to tie the game after the Vineyarders failed to box out on a free throw. With five minutes to go and the game tied, the Vikings switched to a full-court press but Viera and Reppert were able to get around defenders and push the ball up-court.

The home team took a 65-62 lead when E.J. Bennett stole a pass and streaked down the court for an easy lay-up. But the Vineyarders answered right back with a dramatic 3-pointer by the Brewer with 1:20 left on the clock to tie the game, a dagger to the Vikings who buried their heads in their hand and shouted in disbelief.

After each team notched a basket, the Vikings again took a 69-67 lead on a basket by Pina with 48 seconds left on the clock. The Vikings then had a chance to build on their lead with 18 seconds left when Pina went to the line for two free throws, but missed both shots.

Coming out of a time-out, the Vineyarders pushed the ball down the court, and after a frenetic scrum under the basket, the ball somehow wound up in the hands of Brewer, who had tied the game minutes earlier with his dramatic 3-pointer. Falling away from the swatting arms of Pina, he kissed the ball off the glass to hit the shot that tied the game at 69 just as the final buzzer sounded.

“Cody [Brewer] was spectacular . . . his performance in the final minutes speaks for itself. That’s about as clutch as it gets,” coach Joyce said.

The overtime period saw its fair share of dramatics, but was largely a letdown following the thrilling regulation period. The Vikings built a lead of 75-72 in the first few minutes, and Viera fouled out of the game after drawing his fifth foul. The absence of Viera — the team’s spark plug all season — clearly hurt the Vineyarders, and a pair of questionable calls by the referees for traveling seemed to stop any momentum for the visitors.

When Monteiro went to the line in the closing seconds with his team leading 82-76, players from both teams met at half court and exchanged high fives and hugs. Both the teams had fought together in what amounted to a war spread over five periods, and there was clearly more respect and admiration on both sides than hard feelings.

“Of course, the team was disappointed after the loss,” coach Joyce said. “But I think it was clear they respected Wareham for playing such a hard-fought game. A lot of times you will see a team trash-talking after a loss like this, but some of our players actually wished [the Vikings] good luck in the next round [of the state tournament].

“After the game I told them they played a great game and had nothing to be ashamed of . . . I was proud of them,” Coach Joyce said. “They played their hearts out and they left nothing on the court.”