BANGOR — As it turns out, when the Mt. Desert Island boys’ basketball team upset No. 5 Ellsworth in the preliminary round, it was just getting started.

On Saturday afternoon at the Cross Insurance Center, the No. 12 Trojans continued their impressive run, knocking off their second top-five opponent, this time No. 4 Gardiner, 57-53.

“We’ve been making shots, and we’ve been playing together as a team. I don’t think you can find a group of 12 guys that love each other more,” said MDI’s Riley Swanson, who scored a game-high 19 points.

MDI, now 7-13, will face either No. 1 Medomak Valley or No. 8 Maine Central Institute in the Eastern Class B semifinals on Wednesday night. The Tigers end the season at 13-7.

“We had a couple bounces early, so we relaxed a little bit. I think we lost the ballgame at the end because we didn’t play any defense,” Gardiner Coach Jason Cassidy said.

With the score tied at 47 with 21/2 minutes to play, MDI got hot. Aaron Snurkowski hit a running layup to give the Trojans the lead for good. Russell Kropff scored, then added a putback off an Andrew Phelps steal to push MDI’s lead to 53-47 with 1:27 to play.

Kropff scored all eight of his points in the final 2 minutes to help the Trojans seal the win.

“You’ve got to play defense, you’ve got to play as a team to win, and they did a better job of that tonight. They were the better team. We didn’t step up and get stops at the end of the game,” Cassidy said.

Swanson said he felt the game swing in MDI’s favor at the end of the third quarter, when he made a buzzer-beating baseline 3-pointer in front of his bench.

“The guys were all like, there’s no way we’re going to lose. It was like a sign that we’ve got to win this one,” Swanson said.

Gardiner led 11-9 after one quarter, but then went cold from the field, and the Trojans led 19-17 at the half. The smaller Trojans focused on boxing out and trying to limit Gardiner’s transition opportunities.

“They’re a pretty good transition team,” Swanson said.

“At the end of the season, we’ve gotten used to living on our offense, and that killed us tonight, because it wasn’t working,” Cassidy said. “Tonight, everything was a struggle.”

Eli Fish’s 3-pointer for Gardiner tied the game at 41-41 with 4:39 to go, and the teams traded baskets until MDI’s game-winning run. Seth McFarland scored eight of his team-high 18 points for Gardiner in the fourth quarter, and Fish added 13 points. Brad Weston scored nine for the Tigers.

“I just told the guys, this is really the funnest group I’ve ever coached. They’ve given everything we asked,” Cassidy said.