LONDONDERRY — Jackson Cox’s third-chance putback with 4.5 seconds to go capped Londonderry’s late charge to a 42-40 win over Winnacunnet of Hampton in a Division I boys’ basketball quarterfinal Friday night at Londonderry High.

The fourth-ranked Lancers (16-4) advance to Wednesday’s semifinals at Lundholm Gym at the University of New Hampshire, where they’ll take on top-ranked Exeter at 7:30 p.m.

The sophomore guard’s bucket capped an 11-1 run to close the game, most of which happened after senior Jack Schaake, one of the Warriors’ leaders, fouled out with 2:27 to go.

Twice in the final minute, the Lancers converted a steal into a basket. Cole Keegan’s theft with 40 seconds to play gave the Lancers possession in a 40-40 game. They ran the clock down and senior Ethan May pulled up for a jumper, which missed. James Buttafuoco grabbed the offensive rebounds and missed the putback, but the third time was the charm for Cox, who led the Lancers with 13 points.

“They were determined to fight the last two minutes of the game and that showed in the last 13 seconds. And then my sophomore, Jackson Cox, who didn’t have a great game compared to when he played them last time, and that huge putback was just tremendous, so I love the resiliency,” said Lancers coach Nate Stanton.

“I thought we defended pretty well. We got a couple of key steals. We came down and capitalized,” Stanton said.

Trailing 40-38, the Lancers were set up by Buttafuoco’s steal and he finished with a putback of his own offensive rebound to tie the game with 56.4 seconds to go.

“I thought we took care of the ball in the fourth quarter, toward the last three minutes, which is something we struggled with throughout the season,” Stanton said.

The Warriors (15-5) had one last chance to send the game to overtime but senior Ben Allen’s coast-to-coast drive missed the mark as the buzzer sounded.

Allen led all scorers with 15 points. Schaake, who fouled out for the third straight game, had 11. Winnacunnet had a 39-33 when Schaake fouled out, leaving coach Jay McKenna to wonder what might have been.

“This is the toughest part of your season,” McKenna said. “Any time you get into the state tournament, unless you win the whole thing, it’s going to end like this, with crying kids. If you’ve got your five best or you’ve got the end of your bench on the floor, it’s brutal. I mean, look at the guys walking out. They’re all crying. It’s bitter no matter how it goes down.”

When asked if his big man’s presence would have made a difference in Londonderry’s winning bucket, McKenna said, “possibly. Any time you don’t have a great player on the floor it’s going to affect you.”

“All great teams … play defense and they rebound and we couldn’t come up with the rebound when we needed to,” McKenna said. “When you give a good team like that however many shots they got, they’re going to make it.”

Winnacunnet led throughout the middle two quarters, building its edge to 12 with a 30-18 lead with 3:40 to go in the third. But the Warriors picked up their seventh foul with 1:13 to go in the period, and the Lancers took advantage, going to the free-throw line 12 times the rest of the way, making eight of 12.

The first half was a tale of defense and turnovers. Londonderry took a 9-6 lead after a quarter, but the Lancers put up only four points in the second quarter and the Warriors pounced, taking an 18-13 lead into the break. Schaake had seven points in the half and Allen had five.

Londonderry took much better care of the ball in the second half as May, who had a tough shooting night with only six points, turned his attention to distribution. “He’s been a great leader all year long. I thought he adapted well in the fourth quarter,” Stanton said.

“I thought they just kept their composure in the fourth quarter and never gave up,” Stanton said, despite trailing for almost all of the final three quarters. “They’re confident. They’re a heck of a group to coach.”