Former Marine and Newton City Councilor Jake Auchincloss has won a crowded primary race to become the Democratic nominee for the U.S. House seat being vacated by Rep. Joe Kennedy in Massachusetts' 4th Congressional District.

With about 23 percent of the vote, Auchincloss eked out a narrow victory against Brookline progressive Jesse Mermell, his closest rival in the seven-way race. The Associated Press declared Auchincloss the winner Friday at around 1:30 a.m. after a drawn-out vote-counting process in several cities and towns that were overwhelmed by ballots that had been mailed in.

The town of Franklin emerged as a special case after ballots that were supposed to be counted on election night instead sat inside a vault at City Hall. Workers labored to count those ballots overnight as statewide political reporters remained on the scene.

Auchincloss is a 2010 Harvard graduate and served as a captain in the U.S. Marines. He was elected to the Newton City council in 2015  and worked at a cybersecuity startup and at Liberty Mutual's Innovation Lab. Auchincloss defeated fellow Democrats Jesse Mermell, Becky Grossman, Alan Khazei, Natalia Linos, Isshane Leckey, Ben Sigal and Chris Zannetos. He faces Republican Julie Hall, an Air Force veteran, in the Nov. 3 general election. The district is heavily Democratic.

Auchincloss, a moderate Democrat, was briefly registered as a Republican in 2013 and 2014 while he worked to elect Governor Charlie Baker, a detail that his opponents highlighted on the campaign trail.

Nearly 1 million Massachusetts voters cast ballots by mail in the Sept. 1 primary election. A judge on Wednesday approved a petition from Secretary of State Bill Galvin to let towns and cities complete their vote counts.

In Southeastern Massachusetts, the sprawling district encompasses Attleboro, Berkley, Dighton, Easton, parts of Fall River, Freetown, Rehoboth, Seekonk, Somerset, Swansea, Taunton, Lakeville and stretches all the way up to the well-to-do Boston suburbs.

Enter your number to get our free mobile app