SEATTLE — A federal appeals court on Friday gave President Trump a rare legal victory in his efforts to crack down on so-called sanctuary cities, upholding the Justice Department’s decision to give preferential treatment in awarding community policing grants to cities that cooperate with immigration authorities.

The 2-to-1 opinion overturned a nationwide injunction issued last year by a federal judge in Los Angeles. The appeals court said awarding extra points in the application process to cities that cooperate was consistent with the goals of the grant program created by Congress.

“The Department is pleased that the Court recognized the lawful authority of the Administration to provide favorable treatment when awarding discretionary law-enforcement grants to jurisdictions that assist in enforcing federal immigration laws,” the Justice Department said in an emailed statement.

Federal courts have blocked some efforts by the administration to withhold money from sanctuary cities, including an executive order issued by the president in 2017 that would have barred them from receiving federal grants “except as deemed necessary for law enforcement purposes.”