JUNEAU, Alaska — A state court judge on Thursday overturned the results of a northern Alaska legislative election, citing problems with how the primary election was conducted and awarding the race to incumbent Rep. Benjamin Nageak, D-Barrow.

The state responded by appealing Superior Court Judge Andrew Guidi’s decision to the Alaska Supreme Court, Lt. Gov. Byron Mallott said.

Election results had shown that Nageak lost his primary by eight votes to fellow Democrat Dean Westlake in August. But Guidi, in finding errors in how the election was carried out, deducted 12 votes from Westlake and two from Nageak and ordered the Division of Elections to certify Nageak as the winner.

Most of the issues raised by Nageak’s attorneys did not constitute election malconduct, Guidi wrote. But the actions in one precinct did, he said: In Shungnak, voters got both the Republican ballot and the ballot for other parties, including Democrats. State law dictates that a voter only gets one ballot.

In giving voters both ballots, election workers “violated clearly established constitutional rights as well as the requirements of statutory law,” Guidi wrote. They also biased the outcome because this occurred in a precinct that overwhelmingly supported Westlake, he wrote.

None of the Shungnak election workers participated in any training offered by the Division of Elections this year, and there was no evidence that division supervisors followed up, Guidi wrote.

The state had argued that no one who voted did so illegally because the Democratic Party has an open election, meaning Republicans could ask for and receive a Democratic ballot. There was no Republican challenger for the seat.

“This conduct cannot be characterized as an ‘honest mistake,’ as the Division argues, without robbing the term of all meaning and undermining accountability for the conduct of elections,” Guidi wrote.

He deducted “contaminated votes” from each candidate in proportion to the votes that each received in the precinct, decreasing Westlake’s total by 11 and Nageak’s by one.

He further reduced the tally by one each because of the division’s counting of questioned ballots in Kivalina.

Nageak challenged the outcome of the House District 40 race. He faced in Westlake a challenger backed by the state Democratic Party. Nageak, while a Democrat, caucuses with the Republican-led House majority — one of four rural Democrats to do so. One of the others, Rep. Bob Herron, lost his primary to another Democratic party-backed challenger. Seated alongside Nageak’s lawyers was Randy Ruedrich, a former chairman of the state Republican party.

During the recent trial in the case, an attorney for the state conceded errors were made but argued they didn’t meet the threshold to successfully challenge the election result.

In a statement, Mallott, who oversees elections in Alaska, expressed disappointment with Guidi’s ruling. In filing the appeal, he said, the state wants clarity on the issues involved and will follow whatever steps deemed appropriate by the Alaska Supreme Court “to secure a fair election” for Nageak and Westlake.

An attorney for Nageak, Stacey Stone, said Nageak’s team was pleased with Guidi’s decision, But she also noted that the matter was likely to be appealed.

The state Supreme Court already plans to hear arguments in a recount appeal filed by Nageak next Wednesday, and it has said that any appeal of Guidi’s decision would be consolidated into the recount appeal.