Updated Dec. 8 at 6:14 p.m.

Democrat Kristin Kassner jumped into the lead over five-term Republican Rep. Lenny Mirra after a district-wide recount erased her narrow deficit and put her ahead by a single vote, an infinitesimally tight outcome that the incumbent plans to challenge in court.

Mirra led Kassner by 10 votes out of more than 23,000 cast across the North Shore district in the original certified results for the Nov. 8 election, a margin well within the legal threshold that allowed her to file for a recount.

By the time Topsfield officials finished retabulating ballots Thursday from their town's first precinct -- the final batch to be counted -- the overall result flipped and put Kassner up 11,763 to 11,762.

Mirra said he plans to challenge the outcome, which would further extend a monthlong stretch of uncertainty about who will be the next representative for the redrawn North Shore district.

"It'll absolutely be a legal challenge," Mirra said.

Five voters picked other candidates in the race between Kassner and Mirra, and 638 left that field blank on their ballots, Secretary of State William Galvin's office said.

Kassner picked up 10 votes in Ipswich, four votes in Rowley, three votes in Topsfield, a net single vote in Newbury and one vote in Georgetown, according to data provided by Galvin's office. Mirra added a net five votes in Ipswich, three in Topsfield and one in Newbury while losing a vote in Rowley.

"We are not suspicious of anything that ever happened. [The recount] was just really just to ensure that, between humans and machines, we really caught every vote that was counted," Kassner, a Hamilton resident who previously worked as planning director for the town of Burlington, said. "We thank the tremendous outpouring of people that really got involved and mobilized to go through this process this weekend. It's really a true test of democracy."

If the result holds, it would reflect another blow for Republicans, who lost every Massachusetts statewide race including the corner office, and expand the gains Democrats made to their legislative supermajority this cycle.

The updated results will now go to Gov. Charlie Baker and the Governor's Council, which does not plan to meet again until Wednesday, for recertification.

Mirra, a Georgetown Republican, said attorneys for both sides "challenged or questioned several dozen votes" during the recount. Only ballots protested at the time during a recount can then be challenged in court.

"Yesterday, in Rowley, they were able to use five spoiled ballots that all went to my opponent. In no other town did they let us use spoiled ballots," he said, adding that there were several other mail-in votes in Ipswich for which he believes signatures do not match their envelopes.

A battle in court over the validity of individual ballots could thrust the state's voting reforms into the spotlight.

Massachusetts rolled out widespread mail-in voting for the first time in 2020, albeit on a temporary basis, in an attempt to ensure ballot access while minimizing the risks of COVID-19 transmission at polling places. Lawmakers then moved this summer to make that option as well as expanded early voting permanent features.

Mirra in June voted against the compromise bill enshrining permanent mail-in and expanded early voting, as did the rest of the House GOP caucus. Republican Gov. Charlie Baker signed the measure (S 2924) into law.

He also cast the lone opposing vote to the House's decennial redistricting plan, which substantially reshaped the political lines on the North Shore.

Today, Mirra represents Georgetown, Groveland, Merrimac, Newbury, West Newbury and parts of Boxford and Haverhill. The new Second Essex District for which he and Kassner ran stretches further south, covering Georgetown, Hamilton, Ipswich, Newbury, Rowley and part of Topsfield.

Mirra said he "absolutely" believes the updated map played a role in the tight race.

"I got totally screwed in this redistricting. I lost five of my seven towns. Usually, a rep district changes by maybe five percent or 10 percent," Mirra said. "It's an unheard-of amount of change for my district. It was devastating because it's like starting all over. There was no benefit to being the incumbent because we were a complete unknown in these new towns."

The race pitted a Baker-endorsed incumbent, first elected in 2012, against a first-time challenger who touted the support of Attorney General and now Gov.-elect Maura Healey.

Success in the Second Essex District would push Democrats to victory in 133 of 160 House districts, giving them four more seats beginning in January than they held at the start of the current two-year term in 2021.

Democrats might expand their pickup even further to a net gain of five seats depending on how a recount plays out in the First Middlesex District, which stretches through north-central communities near the New Hampshire border.

With the recount complete in five of the district's six communities as of Thursday, Democrat Margaret Scarsdale of Pepperell led Republican Andrew Shepherd of Townsend by 11 votes, according to Galvin's office. Another 4,104 ballots will be recounted in Lunenburg on Saturday.

Although Kassner's apparent margin of victory essentially could not get smaller, it's not unprecedented. In 2019, Boston City Councilor Julia Mejia emerged victorious by a single vote following a recount.

Twelve years ago, a recount narrowed the gap between Democrat Rep. Geraldo Alicea and his Republican challenger, Peter Durant, to a single vote. A Superior Court judge later ruled that an absentee ballot that was rejected should have been counted for Alicea, prompting a special panel of lawmakers to declare the race a tie and order a new special election, which Durant won.

Mirra at least appears to have avoided the fate of former Governor's Councilor Herbert Connolly, who in 1988 arrived to the polls too late to cast a ballot for himself and lost by a single vote. Asked if he voted for himself, Mirra replied, "Of course."

Connolly challenged some ballots, but a court ruled his opponent the victor. His attorney in that matter? None other than veteran state representative William Francis Galvin, who six years later would go on to begin his still-ongoing tenure as the state's chief elections official.