A sharply divided Supreme Court has concluded that certain immigrants or asylum seekers do not have an automatic right to periodic custody or bail hearings.

The 5-3 decision comes as the Trump administration looks to shore up rules governing those seeking permanent entry into the country.

At issue is whether aliens requesting admission to the U.S. who are subject to mandatory federal detention must be afforded court status hearings, with the possibility of release into the country, if the detention lasts more than six months. That could include lawful permanent residents charged with a crime; those detained at the border seeking entry who might lack valid documentation; or those claiming fear of persecution if they return to their home country.

The key plaintiff was Alejandro Rodriguez, held for more than three years without any bond hearing. The Mexican national was convicted of misdemeanor drug possession and joyriding, but fought deportation. He eventually was allowed to stay in the U.S. after his release from custody.

With the help of the American Civil Liberties Union, he sued, claiming his constitutional rights were violated.

In the majority ruling, Justice Samuel Alito said the government’s authority was clear: “Detention during those proceedings gives immigration officials time to determine an alien’s status without running the risk of the alien’s either absconding or engaging in criminal activity before a final decision can be made.”

Alito also accused the three dissenting justices of ignoring the relevant law. “How does the dissent attempt to evade the clear meaning of ‘detain’? It resorts to the legal equivalent of a sleight-of-hand trick.”

Chief Justice John Roberts, and Justices Anthony Kennedy, Clarence Thomas and Neil Gorsuch, supported the judgment.

But Justice Stephen Breyer said the fact these are immigrants in custody does not diminish their right to a hearing.

“The bail questions before us are technical but at heart they are simple,” Breyer said, in an unusual oral dissent read from the bench. “We need only recall the words of the Declaration of Independence, in particular its insistence that all men and women have ‘certain unalienable rights,’ and that among them is the right to liberty.”

Breyer was backed by Justices Ruth Bader Ginsburg and Sonia Sotomayor. Justice Elena Kagan recused from the case back in November, citing an unspecified conflict.

The court avoided resolving other issues raised by the plaintiffs, throwing the case back to the lower courts to decide if the immigration law being challenged is constitutional.

The ACLU said all but about 10 percent of the immigrant claims are settled within six months, and that about 34,000 immigrants on average are being detained at any one time in the U.S.

“The Trump administration is trying to expand immigration detention to record-breaking levels as part of its crackdown on immigrant communities,” said ACLU attorney Ahilan Arulanantham, who argued the Supreme Court case. “We have shown through this case that when immigrants get a fair hearing, judges often release them based on their individual circumstances.”

The Justice Department had no immediate reaction to the court ruling.

Both the Trump and Obama administrations had taken the same position on the bond-hearing question.

The case is Jennings v. Rodriguez (15-1204).