WASHINGTON (Reuters) - The Supreme Court on Tuesday endorsed the U.S. government’s authority to detain immigrants awaiting deportation anytime - potentially even years - after they have completed prison terms for criminal convictions, handing President Donald Trump a victory as he pursues hardline immigration policies.

FILE PHOTO: The Supreme Court is seen in Washington, U.S., May 14, 2018. REUTERS/Joshua Roberts

The court ruled 5-4 along ideological lines, with its conservative justices in the majority and its liberal justices dissenting, that federal authorities could place such immigrants into indefinite detention anytime without the possibility of bail, not just immediately after they finish prison sentences.

The ruling, authored by conservative Justice Samuel Alito, left open the possibility that some immigrants could challenge their detention. These immigrants potentially could argue that the use of the 1996 federal law involved in the case, the Illegal Immigration Reform and Immigrant Responsibility Act, against them long after finishing their sentences would violate their due process rights under the U.S. Constitution.

Most of the plaintiffs in the case are legal immigrants.

The law states the government can detain convicted immigrants “when the alien is released” from criminal detention. Civil rights lawyers in the case argued that the language of the law shows that it applies only immediately after immigrants are released. The Trump administration said the government should have the power to detain such immigrants anytime.

In dissent, liberal Justice Stephen Breyer said the ruling raises serious due process questions.

“It runs the gravest risk of depriving those whom the government has detained of one of the oldest and most important of our constitutionally guaranteed freedoms,” Breyer wrote.

But Alito wrote that it is not the court’s job to impose a time limit for when immigrants can be detained after serving a prison sentence. Alito noted that the court has previously said that “an official’s crucial duties are better carried out late than never.” Alito said the challengers’ assertion that immigrants had to be detained within 24 hours of ending a prison sentence is “especially hard to swallow.”

It marked Trump’s latest immigration victory at the court. The conservative justices also were in the majority in June 2018 when the court upheld on a 5-4 vote Trump’s travel ban targeting people from several Muslim-majority countries.

Tuesday’s decision follows a February 2018 ruling in a similar case in which the conservative majority, over liberal dissent, curbed the ability of immigrants held in long-term detention during deportation proceedings to argue for release.

‘MOST EXTREME INTERPRETATION’

American Civil Liberties Union lawyer Cecilia Wang, who argued the newly decided case for the challengers, said that in both rulings “the Supreme Court has endorsed the most extreme interpretation of immigration detention statutes, allowing mass incarceration of people without any hearing, simply because they are defending themselves against a deportation charge.”

Wang said the ACLU is “looking into follow-up litigation along various avenues.”

Trump has backed limits on legal and illegal immigrants since taking office in January 2017.

Kerri Kupec, a U.S. Justice Department spokeswoman, said administration officials were pleased with the ruling.

The case’s plaintiffs included two legal U.S. 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.

In the two detention case rulings, the Supreme Court reversed the San Francisco-based 9th U.S. Circuit Court of Appeals, a liberal leaning court with jurisdiction over a large part of the western United States that Trump has frequently criticized. In both cases, litigation against the federal government started before Trump took office.

In the latest case, the administration had appealed a 2016 9th Circuit ruling that favored immigrants, a decision it said would undermine the government’s ability to deport immigrants who have committed crimes.

The 9th Circuit had ruled that convicted immigrants who are not immediately detained by immigration authorities after finishing their sentences but then later picked up by immigration authorities could seek bond hearings to argue for their release.

Other regional federal appeals courts that have addressed the issue did not rule the same way as the 9th Circuit and were more in line with the Supreme Court’s ruling. That means immigrants in those regions who were subject to mandatory detention already were not entitled to bond hearings.

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.

In April 2018, conservative Trump appointee Neil Gorsuch joined the court’s four liberals in a 5-4 ruling that could hinder the administration’s ability to step up the removal of immigrants with criminal records, invalidating a provision in another law, the Immigration and Nationality Act.