SAN FRANCISCO — A federal appeals court decided unanimously Thursday that the Trump administration may not force Los Angeles to help the government deport immigrants as a condition of receiving a federal police grant.

A panel of two Republican appointees and one Democrat of the U.S. 9th Circuit Court of Appeals said federal law did not permit the Trump administration to impose the conditions.

The decision involved the Edward Byrne Memorial Justice Assistance Grant Program, the primary provider of federal aid to local and state law enforcement agencies.

Congress authorized the program in 2005 to help law enforcement pay for personnel, supplies and other services. It is administered by the U.S. Department of Justice.

In 2017, the Trump administration imposed two new requirements on the grant. One required recipients to notify immigration authorities before releasing immigrants from jail. The other said recipients had to give federal agents access to correctional facilities to meet with immigrants who might be in the country without authorization.

The city of Los Angeles sued, saying it did not cooperate with immigration agents because doing so would discourage immigrants from helping police in fighting crime.

A district judge blocked the requirements, and the Trump administration appealed to the 9th Circuit.

Judge Sandra S. Ikuta, writing for the panel, said the 9th Circuit agreed with two other circuit courts that the law authorizing the grants does not give the Justice Department “broad authority to impose any condition it chooses.”

Ikuta, appointed by President George W. Bush, was joined by Judge Jay S. Bybee, also appointed by Bush, and Judge Kim McLane Wardlaw, a Clinton appointee.

Wardlaw wrote separately, saying she agreed the conditions were unlawful but criticizing the majority’s analysis as “contrary to every other court to have addressed the issue in a reasoned opinion.”

Los Angeles City Atty. Mike Feuer called Thursday’s decision “a victory for public safety on our streets and for the Constitution.”

“We will continue to fight the Trump administration’s unlawful overreach and to stand up for the best interests of L.A. residents,” he said.

Los Angeles uses the federal grant to support local criminal law enforcement and drug treatment and enforcement programs.

The immigration conditions would have denied the grant to hundreds of sanctuary cities.

Last year, the U.S. 7th Circuit Court of Appeals upheld an injunction preventing the federal government from applying the immigration conditions. That ruling stemmed from a lawsuit by the city of Chicago.

In another decision this year, the 3rd Circuit also decided the conditions were not authorized by law. That case was brought by the city of Philadelphia.

The grants can be used for technical assistance, strategic planning, research and evaluation, data collection, training, personnel, equipment, forensic laboratories, supplies, contractual support and criminal justice information systems.

The law authorizes $1.1 billion in grants, but funding is generally significantly lower.

According to the National Criminal Justice Assn., Congress appropriated $830 million for fiscal year 2002, but in later years funding for the grants was about $500 million.