AUGUSTA – In his first season as Lawrence High School’s boys’ basketball coach, Mike McGee coached the Bulldogs to one of the biggest upsets of his career, beating Waterville in the Eastern Class A final.

On Friday night, McGee almost did it again. It took a buzzer-beating 30-foot 3-pointer by Hampden Academy freshman Nick Gilpin to beat Lawrence and give the Broncos a 40-39 win in the Eastern A final.

It was the closest game of the season for the Broncos, who had defeated every previous opponent by at least 11 points.

Hampden (21-0) will play the winner of Saturday night’s Western Class A final between Bonny Eagle and South Portland.

Lawrence ends the season at 16-5.

Gilpin’s shot gave Hampden its first lead since an 8-7 lead early in the first quarter, and capped a crazy final 10 seconds. With 10 seconds to play, Zach Gilpin, Nick’s older brother, sank a pair of free throws to tie the game at 37-37.

Lawrence’s Xavier Lewis made a baseline jumper with 4.2 seconds left to give Lawrence the lead and was fouled on the play. But Lewis missed the free throw, the Bulldogs’ sixth missed foul shot of the fourth quarter, setting up Nick Gilpin’s heroics.

Lawrence led by four points, 37-33, with 1:24 to play when Spencer Carey made a layup. Carey scored 12 of his game-high 18 points in the second half.

Cam Scott scored to cut Lawrence’s lead to two points with 53 seconds left, and Aaron LaFrance missed a pair of free throws for the Bulldogs with 27.2 seconds to play.

Right from the start of the game, the Bulldogs made sure to slow the pace.

Lawrence played deliberate offense, often passing the ball around the perimeter waiting for the right shot. A Nick Noiles 3-pointer gave Lawrence a 14-10 lead with 2:12 left in the first half.

Lawrence led by as many as seven points in the third quarter, 24-17, when Lewis (10 points) made a 3-pointer. Hampden tied the game at 28 when Brian Fickett converted a three-point play with 6:50 left in the third. The Broncos tied it again on a Zach Gilpin (13 points) basket with 2:47 left in the third, 31-31, but Lawrence answered with a pair of Matt Saunders free throws and a Carey bucket.