A closely divided Supreme Court sided with the Trump administration in its efforts to combat illegal immigration in a 5-4 ruling Tuesday.

In the majority opinion by Justice Samuel Alito that split along ideological lines, the high court held that federal immigration authorities can detain illegal immigrants released from prison or jail pending their deportation, even if it’s not immediately upon, or shortly after, their release.

Alito was joined in his ruling by fellow conservatives Chief Justice John Roberts and Justices Clarence Thomas, Neil Gorsuch, and Brett Kavanaugh. Justices Stephen Breyer, Ruth Bader Ginsburg, Sonia Sotomayor, and Elena Kagan dissented.

Breyer, writing for the court’s liberal bloc, warned that the “greater importance in the case lies in the power that the majority’s interpretation grants to the government.”

“It is a power to detain persons who committed a minor crime many years before. And it is a power to hold those persons, perhaps for many months, without any opportunity to obtain bail,” he wrote.

The court ruled on arguments in two separate class-action cases from green-card holders from California and Washington state.

Alito wrote that “neither the statute’s text, nor its structure” backed up the plaintiffs’ arguments that immigrants facing deportation should get a hearing before being detained, unless they were picked up immediately after a prison sentence.

The American Civil Liberties Union, which represented the immigrants, criticized Tuesday’s ruling.

“For two terms in a row now, 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,” Cecillia Wang, the ACLU’s deputy legal director, said in a statement. “We will continue to fight the gross overuse of detention in the immigration system.”

The 9th Circuit Court of Appeals had sided with the plaintiffs against the Trump administration, which appealed the ruling.

“Once again, the Supreme Court overturned a 9th Circuit’s decision that was completely outside the plain text of federal immigration law,” said Hans von Spakovsky, senior legal fellow with The Heritage Foundation. “This provision ensures that dangerous criminals and dangerous terrorists won’t be let out into the streets of America.”