A federal judge issued a preliminary injunction Friday barring the Trump administration from imposing requirements that local jurisdictions cooperate with immigration agents to receive anti-gang funds.

U.S. District Judge Manuel Real issued the injunction against the Department of Justice in response to a lawsuit filed by the city of Los Angeles in July seeking to prevent the government from awarding federal police grants based on cooperation with immigration enforcement.

Friday’s ruling was another setback in the administration’s campaign to crack down on illegal immigration and require cities like Los Angeles, whose police department does not provide information to Immigration and Customs Enforcement, to comply.

“The Court’s action is a win for public safety in Los Angeles, and once again confirms that our nation’s system of checks and balances works,” said Los Angeles City Atty. Mike Feuer.

The Justice Department annually doles out funds from the Edward Byrne Memorial Justice Assistance Grant to states and cities to support law enforcement efforts against gangs. Since 1997, Los Angeles has annually received more than $1 million in such funds, including $1.8 million in 2016. The city was eligible for about $1.9 million in 2017, but Atty. Gen. Jeff Sessions announced in July of that year that under an executive order, all of the anti-gang grant money would hinge on new immigration compliance requirements.

Judge Real found that the Justice Department had no authority to place such conditions on the grant money.

“To further show that the program is not to be administered according to the Attorney General’s discretion, Congress structured the Byrne JAG program as a formula grant,” Real wrote in his decision. “As stated above, the authority granted to the Attorney General with the Byrne JAG statute regarding distribution of funds is extremely limited and leaves little room for discretion.”

The ruling echoes a permanent injunction Real issued in April that imposed a nationwide ban on a Justice Department policy that gave preferential consideration to obliging police departments applying for a separate Community Oriented Policing Program grant. Feuer cited that ruling as a precedent to end controls on the anti-gang monies.

Federal officials called that decision “overbroad and inconsistent with the rule of law.”

The Justice Department has argued it has the “lawful discretion to give funds to jurisdictions that promise to cooperate with federal immigration authorities seeking information about illegal aliens who have committed crimes.”

Los Angeles and other cities have sought a share of the anti-gang funds to bolster neighborhood policing and intervention programs to reduce gang violence. The Los Angeles Police Department has used the funds to battle the MS-13 gang that has its roots in the city and is often cited by the Justice Department as illustrating the need for strong immigration and crime policies.

Friday’s decision is the latest in an ongoing legal struggle between L.A. and the administration. In the last year, immigration agents have dramatically ramped up the number of people they arrest and deport.

President Trump and Sessions have been infuriated by so-called sanctuary cities such as Los Angeles that, to varying degrees, refuse to help federal authorities enforce immigration laws because of legal and moral concerns over cooperating. Sessions, after initially publicly shaming objectors, is now seeking to withhold funds.

The LAPD for many decades has abided by rules that sharply restrict an officer’s ability to inquire about a person’s immigration status. Officials argue that in a city with a large population of immigrants living in the country illegally, the rules are necessary to assure immigrants that they can report crimes without fear of being questioned about their status.

Since Trump took office, former LAPD chief Charlie Beck and current Chief Michel Moore have been particularly assertive on the need for the department to build trust with the city’s immigrant communities.