CAPE ELIZABETH — Yarmouth didn’t relinquish its state title easily, but Cape Elizabeth’s resilience proved the difference Thursday in a thrilling Class B South baseball quarterfinal.

Carson Sullivan drove in a run with a bases-loaded infield single in the ninth inning, giving the second-seeded Capers a 6-5 victory against the seventh-ranked Clippers.

It came after the Capers (12-5), who have lost several late- inning leads this spring, were staggered by Yarmouth’s five-run seventh inning that tied the game.

But for the third time this year, they found a way to get past the Clippers (10-8).

Cape Elizabeth will be home against third-seeded Greely (11-6) in the semifinals Saturday, with the time to be determined.

In the bottom of the ninth, Brendan Tinsman drew a leadoff walk, stole second base, moved to third on a groundout and scored on Sullivan’s one-out single.

“It was a great game to be a part of,” said Capers Coach Andy Wood. “We knew Yarmouth would never give up. They have a great program.”

For much of the game, Cape Elizabeth starting pitcher Sean Agrodnia was the story. He didn’t allow a baserunner until hitting Jackson Caruso with a pitch with one out in the fifth, and didn’t surrender a hit until Aidan Hickey’s single with one out in the sixth.

By then the Capers had a 5-0 lead, thanks to a Tinsman triple and Agrodnia RBI single in the first, then a four-run fifth that featured three Clipper errors, a squeeze bunt from Alec Riggle and an RBI single from Ryan Weare.

But in the seventh, two outs from defeat and its season on the line, Yarmouth came to life.

Ben Norton and Caruso singled, and Dom Morrill, the Clippers’ starting pitcher, drew a walk to load the bases.

After Toby Burgmaier singled in a run, Hickey tripled down the left-field line to cut the deficit to one.

Sullivan replaced Agrodnia and was greeted by a squeeze bunt by Jason Lainey that brought in Hickey to tie the score.

After the Capers dodged trouble in both the eighth and ninth innings, they won it in the bottom of the ninth.

Tinsman, who didn’t see a hittable pitch after his first-inning triple, drew a four-pitch walk before stealing second base.

“I thought I’d get at least one pitch to hit but I’ll take it,” Tinsman said.

Agrodnia’s grounder moved him up and after Riggle reached on an infield hit with Tinsman holding, Jameson Bakke was intentionally walked, setting the stage for Sullivan.

His infield single slipped past Yarmouth reliever Jack Romano to give Cape Elizabeth the victory.

“I hadn’t gotten a hit all game and I knew I had to get one there,” said Sullivan. “I made sure I hit it on the ground. I was just hauling to first and I heard the yells.”

Yarmouth got two hits from Hickey and continued to prove it has a program that won’t give up easily.

“The reason why I coach is because I want to make an impact on these kids in some way,” said Clippers Coach Marc Halsted. “Yarmouth baseball, by and large, makes a positive impact on kids. We put our heads down and came back.”