The Trump administration can withhold millions of dollars from law enforcement agencies in states and cities that do not cooperate with U.S. immigration authorities, a federal appeals court ruled on Wednesday.

The decision, by the United States Court of Appeals for the Second Circuit in Manhattan, was the first by an appellate court to side with the administration’s argument that it can impose conditions on the release of the money, which comes in the form of grants.

Three other appeals courts have previously affirmed lower court rulings that it was unlawful for the White House to tie the grant money to state and local governments’ cooperation with the federal authorities.

Administration officials hailed the ruling.

“Today’s decision rightfully recognizes the lawful authority of the attorney general to ensure that Department of Justice grant recipients are not at the same time thwarting federal law enforcement priorities,” Alexei Woltornist, a Justice Department spokesman, said.