YARMOUTH — Cody Cook provided the chance, John Thoma provided the tying touchdown pass and Andrew Beatty provided the winning kick Friday night.

Together they helped Yarmouth to a wild 37-36 victory against Cape Elizabeth in a Class C South game between unbeaten teams.

“Yarmouth and Cape always have games like this,” said Yarmouth Coach Jason Veilleux.

Well, maybe not quite like this.

After Ben Ekedahl kicked a 24-yard field goal to give the Capers (6-1) a 36-30 lead, Cook returned the kickoff 37 yards to set up the winning drive.

Thoma then took over, completing 4 of 5 passes, the last a 6-yarder to Cook in the corner of the end zone with 28 seconds left to tie the game.

Beatty then won it with his point-after kick to give the Clippers (7-0) the likely top seed for the regional playoffs, although each team has one game remaining in the regular season.

Thoma, a junior, threw two touchdown passes in the fourth quarter.

Cape controlled the third quarter and a good portion of the fourth with a running game featuring Matt Graham. The Capers led 33-23 after Graham’s 42-yard scoring run with 3:14 left in the third quarter.

But the Clippers weren’t going to be denied. “This team has a lot of heart,” said Cook.

The Clippers needed all of it. Leading 33-30, the Capers faced a fourth-and-goal on the Yarmouth 7 and opted for the field goal before the Clippers’ final drive. Building a six-point lead seemed like good strategy because Beattty has a strong leg and kicked a 43-yarder as time expired in the first half.

Cape took the possibility of a tying field goal away and banked on its defense to keep the Clippers out of the end zone. Yarmouth’s offense had stalled for most of the second half.

But Cook’s return – he broke tackles and spun away – changed all that.

“I was just trying to get as far down the field as I could,” said Cook. “We have a very good team but if someone had told me at the start of the season that we would be 7-0, I don’t know if I would have believed him.”

With the ball on the Cape Elizabeth 42, Thoma passed to Cook for 18 yards on second down. Thoma then hit Noah Colby-George for 8 yards, then Jack Snyder for 12 to the 6.

Thoma’s first-down pass was deflected and on second down, he lofted a perfect pass to Cook in the corner of the end zone.

“John put enough air on it that the defender didn’t have a chance,” said Cook.

After Beatty’s winning point after, Yarmouth squibbed the kickoff. Cape got the ball at its 35 with 21 seconds left. Jack O’Rourke completed a 10-yard pass but the next one, a desperation throw, was intercepted by the Clippers as time expired.

Trailing by 10, the Clippers got back in the game when Thoma threw a 7-yard touchdown to Snyder with 7:26 left in the game.

The first half was wide open. Cape scored on the opening kickoff as the kicking team. The ball popped out of the returner’s hands right to Brett McAlister of Cape Elizabeth, who ran it in from the 25.

Cape led 6-0 after only 10 seconds.

The rest of the half stayed as wild and unpredictable as the opening seconds. It was a passing show between Thoma and O’Rourke, and Cape receiver Nate Ingalls caught three touchdown passes in the first half – a 14-yarder, an 81-yarder and a 29-yarder.

Thoma completed 12 of 19 passes for 175 yards and one touchdown in the first half. O’Rourke was 6 of 11 for 179 yards in the half.

Cape’s running game then took over in the second half with Graham and Ryan Weare pounding out the yardage. Graham finished with more than 100 yards rushing.