PHOENIX (AP) — An Arizona judge ruled Tuesday that Republican Abraham Hamadeh can proceed with his lawsuit challenging the results of the election for attorney general, which he lost in one of the closest elections in state history.

Mohave County Superior Court Judge Lee Jantzen ruled that Hamadeh can attempt to prove his case during a trial scheduled for Friday. Under Arizona law, he faces the high bar of proving not just that election officials erred but that he would have won without their misconduct.

Hamadeh lost to Democrat Kris Mayes by 511 votes out of 2.5 million. His lawsuit alleges that problems with printers in Maricopa County led to a series of issues that disenfranchised voters. He also alleges his race was affected by improper handling of ballots that were duplicated or adjudicated by humans because they could not be read by tabulators.

In his ruling allowing Hamadeh to proceed on those grounds, Jantzen dismissed his claim that the procedures for handling mail ballots are unconstitutional. Jantzen said the claim should have been brought before the election.

But Jantzen said Hamadeh can inspect ballots in Maricopa, Pima and Navajo counties. Mayes won Maricopa and Pima counties, home to Phoenix and Tucson. Hamadeh won Navajo County, though it’s home to a large Native American population that heavily favored Mayes.

Jantzen made no comment on the merits of Hamadeh’s claims, but ruled that he’s entitled to gather witnesses and evidence in an attempt to prove them.

The Arizona Supreme Court ruled nearly a century ago that mistakes by election officials, even big ones, are not sufficient on their own to overturn an election; the losing candidate must prove the mistakes affected the result.

Kari Lake, a Republican who lost the race for governor, also will attempt to prove she should have won during a trial scheduled to begin on Wednesday. Lake faces the even more daunting challenge of overcoming a 17,000 vote deficit.