A federal judge on Wednesday rejected the Trump administration’s attempt to require California election officials to separate mail ballots from roughly 20,000 people the government alleges are not U.S. citizens. The ruling came less than a week before the Nov. 3 midterm elections, which will determine control of the House and Senate.

U.S. District Judge David Carter said the requested intervention conflicted with constitutional principles that give states authority to conduct elections. In his 26-page decision, he warned that granting the request could allow either political party to disrupt elections for political purposes and potentially deprive more than 20,000 registered Californians of their voting rights.

At Tuesday’s hearing, Carter questioned why prosecutors could not pursue cases after the election against people they believed had voted illegally, instead of risking the exclusion of lawful votes. Returned ballot envelopes contain identifying information that could support prosecutions, he noted. He also described the proposed separation of ballots during voting as a major alteration of election procedures.

The Justice Department sued California, Secretary of State Shirley Weber and Los Angeles County election official Dean Logan earlier this month. Before filing suit, it gave election officials 48 hours to review a list of suspected noncitizens and sought to prevent their ballots from being counted until citizenship was confirmed. California officials challenged both the demand and the list’s accuracy. The state has more than 23 million registered voters.

The administration also sought intervention from the 9th U.S. Circuit Court of Appeals on Friday. In a 2-1 ruling Monday, that court found Carter had not been given sufficient opportunity to consider temporary relief. Carter, who was appointed by former President Bill Clinton, issued his decision Wednesday.

Justice Department lawyers argued that counting ballots cast by noncitizens could dilute citizens’ votes and undermine congressional efforts to safeguard elections. Bill Essayli, the top federal prosecutor in Los Angeles, emphasized public confidence in elections and said the administration was not seeking to cancel ballots. Both federal and California law bar noncitizens from voting.

California officials described the lawsuit as politically motivated and intended to undermine confidence in the state’s results. Deputy Attorney General Anne Bellows warned that the requested order would disrupt election operations and risk disenfranchising voters. State lawyers also questioned whether the government relied on outdated registration information. The administration said it supplements voter data through a third-party service.

Los Angeles County lawyers said manually checking ballot envelopes against the government’s list could not be completed by the end of the election period. Only slightly more than 7,000 listed records had county addresses. A county review of 200 records found that more than half involved canceled or inactive registrations for which no ballot was mailed. County officials also said just over 38% of the sample who reported a birthplace listed the United States.

U.S. Citizenship and Immigration Services disputed the birthplace findings. Agency official Nicolas Bartell said its review of immigration records showed none of the 200 people were born in the United States. He separately acknowledged that an ongoing analysis had identified roughly 189 records with minor discrepancies on the larger list sent to California.

California began mailing ballots in early October. More than 3.5 million mail ballots have been returned statewide, and Los Angeles County has processed over 550,000. The dispute is part of the administration’s broader effort to expand federal control over elections. Trump has repeatedly alleged that Democratic-led states have noncitizens on their voter rolls, although noncitizen voting is rare.