A lawsuit brought by President Trump’s campaign that sought to block the certification of Pennsylvania’s election results was dismissed by a federal judge on Saturday evening.

U.S. District Judge Matthew W. Brann granted a request from Pennsylvania Secretary of State Kathy Boockvar to dismiss the suit, which alleged that Republicans had been illegally disadvantaged because some counties allowed voters to fix errors on their mail ballots.

The judge’s decision, which he explained in a scathing 37-page opinion, was a thorough rebuke of the president’s sole attempt to challenge the statewide result in Pennsylvania.

Brann wrote that Trump’s campaign had used “strained legal arguments without merit and speculative accusations” in its effort to throw out millions of votes.

“In the United States of America, this cannot justify the disenfranchisement of a single voter, let alone all the voters of its sixth most populated state,” Brann wrote.

In a statement, Trump’s attorney, Rudolph W. Giuliani, and legal adviser Jenna Ellis said they would appeal the decision and expected the case to reach the Supreme Court. “We are disappointed we did not at least get the opportunity to present our evidence at a hearing,” their statement said.

Trump was beaten in Pennsylvania by Joe Biden, who currently holds a lead over the president of more than 81,000 votes. Counties are due to file their official results Monday to Boockvar, who will then certify the statewide tallies.

Sen. Patrick J. Toomey (R-Pa.) said in a statement after Brann’s decision that Trump had “exhausted all plausible legal options” in the state and acknowledged that Biden won the election. “I congratulate President-elect Biden and Vice President-elect Kamala D. Harris on their victory,” said Toomey.

The lawsuit’s dismissal concluded a tumultuous 12-day legal bid by the president to overturn the popular vote in one of the election’s hardest-fought battlegrounds.

Giuliani personally took charge of the case and appeared at a hearing Tuesday in Williamsport, Pa., in an attempt to justify it. Five other attorneys who represented the president withdrew from the case.

The president’s defeat was the latest in setbacks that he has suffered in a scramble to overturn losses in key states including Arizona, Georgia, Michigan, Nevada and Wisconsin.

In Pennsylvania, Trump’s campaign sued Boockvar and a group of counties won by Biden, alleging that they had violated the campaign’s constitutional rights by allowing voters to “cure” administrative errors on their mail ballots.

Brann wrote on Saturday that Trump’s attorneys had haphazardly stitched this allegation together “like Frankenstein’s Monster” in an attempt to avoid unfavorable legal precedent.

In trying to depict “ballot curing” as illegal, Trump’s attorneys misstated a decision by Pennsylvania’s Supreme Court. Brann noted in his order Saturday that the court had in fact “declined to explicitly answer whether such a policy is necessarily forbidden.”

The president’s campaign sued together with two voters from counties that Trump won, both of whom had their mail ballots rejected because of administrative errors.

Brann wrote on Saturday that throwing out the election result would not reinstate the pair’s right to vote. “It would simply deny more than 6.8 million people their right to vote,” the judge wrote.

Giuliani and Ellis described Brann late Saturday as an “Obama-appointed judge,” referring to his appointment to the federal bench by Trump’s Democratic predecessor in 2012. But Brann is a registered Republican and a former member of the conservative Federalist Society. Toomey, who played an influential role in his appointment, said Brann was “a longtime conservative Republican whom I know to be a fair and unbiased jurist.”

Toomey urged Trump to accept defeat and facilitate the transition to the Biden administration. Trump has refused to concede and falsely insists that he won the election.

Trump’s lawsuit in Pennsylvania initially included formal allegations that Boockvar and Democratic-leaning counties also violated the campaign’s rights by preventing Republican observers from watching votes being counted, which the defendants denied.

Those claims were scrapped in a revised version of the suit filed last Sunday. Giuliani and other Trump advisers initially denied that the claims had been dropped, then said they had “strategically decided to restructure” the suit, before finally saying in court filings that the claims were removed by mistake.

Giuliani asked the judge for permission to restore the deleted claims about count observers in a proposed third version of the lawsuit, but his request was dismissed by Brann along with the rest of the campaign’s legal effort. The judge said Trump’s campaign did not have standing to bring the lawsuit but that even if it had standing it would have failed based on the merits of its case.

The suit’s dismissal left Trump without even a long-shot strategy for overturning his defeat to Biden in Pennsylvania, which the president has baselessly attributed to fraud.

State law requires Boockvar and Gov. Tom Wolf, both Democrats, to certify the election results and appoint the state’s presidential electors based on the popular vote. The leaders of the state’s Republican-controlled legislature have said they will do nothing to interfere with that process, even as some Trump supporters have urged them to sabotage it.

The state’s Supreme Court is considering an appeal from Trump’s campaign that seeks to throw out about 8,000 ballots in Philadelphia where voters did not include details such as the date on their ballot envelopes.

Earlier on Saturday, a group of Republicans, led by Rep. Mike Kelly (R-Pa.), filed a lawsuit in the state’s Commonwealth Court that seeks to block certification of the results on the grounds that the 2019 state legislation creating a universal vote-by-mail system was unconstitutional.

Trump said in a tweet on Saturday that Kelly’s legal effort was “not at all frivolous.”

Aaron Schaffer and Keith Newell contributed to this report.