A federal judge on Tuesday barred President Donald Trump from deploying National Guard and other military troops in California to execute law-enforcement actions there, including making arrests, searching locations, and crowd control.

The ruling came in connection with a lawsuit filed in early June by the state of California challenging Trump’s and Defense Secretary Pete Hegseth’s deployment of the Guard and Marines to deal with protests in Los Angeles over the Trump administration’s immigration enforcement policies.

Judge Charles Breyer said that Trump’s deployment of thousands of National Guard troops and 700 Marines to L.A. violated the federal Posse Comitatus Act, which bars U.S. Military forces from enforcing the law domestically.

Breyer’s ruling in U.S. District Court in San Francisco is limited to California, and the judge stayed the decision until Sept. 12 to give the Trump administration time to appeal it.

But it comes as Trump has considered deploying National Guard troops to other U.S. cities to deal with crime, including Oakland and San Francisco. In mid-August, Trump placed Washington, D.C.’s police force under federal control and deployed National Guard troops in that city to address what he claims is a rampant crime problem.