By Dietrich Knauth and Tom Hals (Reuters) -A federal judge on Tuesday blocked U.S. President Donald Trump's administration from using the military to fight crime in California, as the Republican president threatens to send troops to more U.S. cities including Chicago. San Francisco-based U.S. District Judge Charles Breyer found that the Trump administration violated a law known as the Posse Comitatus Act with its June deployment of 4,000 National Guard and 700 active duty U.S. Marines to Los Angeles. The law sharply limits the use of federal troops for domestic enforcement. The decision dealt a setback to Trump's push to expand the role of the military on U.S. soil, which critics say is a dangerous expansion of executive authority that could spark tensions between troops and ordinary citizens. Breyer put the ruling on hold until September 12. The Trump administration is likely to appeal. Neither the Pentagon, the Justice Department nor the White House immediately responded to requests for comment. The injunction applies only to the military in California, not nationally. But the judge said that Trump's stated desire to send troops to Chicago and other cities provided support for his ruling, noting that the president said at an August 27 cabinet meeting that he had the right to "do anything I want to do ... if I think our country is in danger." Trump has said the troops were needed in Los Angeles to protect federal agents carrying out immigration enforcement, after large-scale immigration raids triggered protests. "There is no question that federal personnel should be able to perform their jobs without fearing for their safety," wrote Breyer, who was nominated to the bench by Democratic President Bill Clinton and is the brother of former Supreme Court Justice Stephen Breyer. "But to use this as a hook to send military troops alongside federal agents wherever they go proves too much and would frustrate the very purpose of the Posse Comitatus Act." The Los Angeles deployment drew wide condemnation from Democrats, who said Trump was using the military to stifle opposition to his hardline immigration policies. "The people of California won much needed accountability against Trump's ILLEGAL militarization of an American city!" California Governor Gavin Newsom, a prominent Democrat who brought the lawsuit, wrote on X on Tuesday. Trump has since deployed the National Guard to Washington, D.C., a federal district where Trump wields exceptional power, and said he may send troops to Chicago, the nation's third-largest city. The Republican president has cited crime rates to justify the need for federal troops. Washington and Chicago, like many places across the U.S., experienced crime spikes in the wake of the pandemic, but crime is on a declining trend in both cities. 'UNPRECEDENTED SHIFT' At a three-day trial last month, lawyers from the California attorney general's office tried to show that the troops had performed police functions -- including setting up security perimeters and detaining two people -- and were not needed in the first place. They warned that a ruling for the Trump administration would "usher in a vast and unprecedented shift in the role of the military in our society." The Trump administration countered that the U.S. Constitution permits presidents to use troops to protect federal personnel and property as an exception to the Posse Comitatus Act. The administration's lawyers tried to show that the troops only acted to protect federal agents from perceived threats and stayed within their legal limits. The administration still had several hundred soldiers in Los Angeles when the trial took place, although the protests had long died down. The troops were used for security during raids on marijuana farms outside the city and as a show of force to deter protests at a popular park during an operation by immigration agents, according to evidence shown at trial. About 300 National Guard troops remain deployed to Los Angeles, and the Trump administration has said they would stay there at least until November. (Reporting by Tom Hals in Wilmington, Delaware and Dietrich Knauth in New York; Additional reporting by Jonathan Stempel and Jack Queen in New York; writing by Susan Heavey and Luc Cohen, Editing by Rosalba O'Brien and Noeleen Walder)