A divided Supreme Court on Tuesday backed the government’s authority to lock up immigrants awaiting deportation after they get out of prison following criminal convictions, giving President Trump a win in his war on illegal immigration.

The court ruled 5-4, with the conservative justices in the majority and liberal justices dissenting, that the feds could pick up such immigrants and lock them up anytime, not just immediately after they finish their time behind bars.

The ruling, authored by conservative Justice Samuel Alito, left open the possibility of immigrants challenging the 1996 federal law involved in the case — the Illegal Immigration Reform and Immigrant Responsibility Act — on constitutional grounds.

They could argue that their rights to due process would be violated if they were still detained long after they completed their sentences.

The law at issue states that the government can detain convicted immigrants “when the alien is released” from criminal detention.

Civil rights lawyers for two groups of plaintiffs argued that the language of the law shows that it applies only immediately after immigrants are released.

Team Trump countered that the government should have the power to detain such immigrants anytime.

It is not the court’s job, Alito wrote, to impose a time limit for when immigrants can be detained after serving a prison sentence.

Alito noted that the court repeatedly has said in the past that “an official’s crucial duties are better carried out late than never,” Reuters reported.

Alito said the challengers’ assertion that immigrants had to be detained within 24 hours of ending a prison sentence is “especially hard to swallow.”

In dissent, liberal Justice Stephen Breyer questioned whether Congress “meant to allow the government to apprehend persons years after their release from prison and hold them indefinitely without a bail hearing.”

The administration had appealed a lower court ruling in the case that favored immigrants, a decision it said would undermine the government’s ability to deport those who have committed crimes.

The plaintiffs included two legal US residents involved in separate lawsuits filed in 2013, a Cambodian immigrant named Mony Preap convicted of marijuana possession and a Palestinian immigrant named Bassam Yusuf Khoury convicted of attempting to manufacture a controlled substance.

Under federal immigration law, immigrants convicted of certain offenses are subject to mandatory detention during their deportation process.

They can be held indefinitely without a bond hearing after completing their sentences.

The San Francisco-based 9th US Circuit Court of Appeals, a liberal-leaning court Trump has slammed in other cases, ruled in 2016 that convicted immigrants who are not immediately detained by immigration authorities after finishing their sentences cannot later be placed into indefinite detention awaiting possible deportation.

The 9th Circuit said such immigrants could seek bond hearings to argue for their release.

With Reuters