LANSING, Mich. — A federal judge in California has blocked a rule that Michigan, seven other states and four big-city school districts said would unlawfully allow too much pandemic relief aid to be diverted from K-12 public schools to private ones.

Judge James Donato ruled late Wednesday that the Education Department “went well beyond” its authority in trying to replace a funding formula mandated by Congress “with ones of its own choosing.” The decision came days after a different federal judge issued a similar injunction in a lawsuit filed by Washington state.

Michigan has said the rule could cost its public schools $16.5 million, including $2.6 million each in Detroit, the state’s largest district, and Grand Rapids, another big district. Donato wrote that if the state lost that much funding, it would be the equivalent of laying off 466 teachers in Flint.

Michigan Attorney General Dana Nessel, a Democrat who has helped lead the lawsuit along with California Attorney General Xavier Becerra, said Thursday that the “money was meant to assist the nation’s public schools that are most in need of financial support,” but Education Secretary Betsy DeVos’ policy “does the exact opposite.”

The ruling temporarily halted the U.S. government from implementing the rule in Michigan, California, Hawaii, Maine, Maryland, New Mexico, Pennsylvania and Wisconsin; Washington, D.C.; and school districts in New York City, Chicago, Cleveland and San Francisco.

Under the rule, school districts were ordered to set aside a portion of their $13 billion in aid for private schools using a formula based on the total number of private school students in the district. The policy has been contested by public school officials who say the funding should be shared based on the number of low-income students at local private schools rather than their total enrollments.

That is how funding is shared with private schools under other federal rules that Congress referenced in the legislation that created the rescue aid. The rule provides an exception. Public schools can use the low-income formula if their own relief funding is used entirely on the district’s low-income students.

Paul Long, president and CEO of the Michigan Catholic Conference, said the judicial decision was disappointing but not unexpected.

“Clearly the attorney general went out to California to find a favorable ruling that discriminates against nonpublic schools,” he said. “Congress included nonpublic schools in the CARES Act to ensure all students are treated equally, without prejudice due to the school they attend.”