The Supreme Court ruled Tuesday that the government can detain immigrants with past criminal records even after they have completed their prison terms, issuing a narrow verdict that sided with the Trump Administration’s pursuit of hardline immigration policies.

The 5-4 decision was led by the court’s conservative justices and dissented by its liberal wing. The ruling reverses a determination by the U.S. Court of Appeals for the 9th Circuit, which stated that migrants can only be put in immigration detention within 24 hours of their release from criminal custody, as opposed to months, or even years later.

The case’s lead plaintiff, Cambodian refugee Mony Preap, was a legal permanent resident with two drug convictions. He was detained, and faced possible removal proceedings in 2013, years after being released from criminal custody, according to the court document.

The conservative justices argued that the earlier ruling “spare[s] terrorist aliens from the rigors of mandatory detention” and would be “gentler on terrorists than it is on garden-variety offenders.”

Justice Samuel Alito said the fact that “the alien must be arrested on the day he walks out of jail” is “especially hard to swallow.”

This “unsparing deadline” will often “be missed for reasons beyond the Federal Government’s control,” he said, adding that the majority ruling was to ensure homeland security officials would not be constrained.

Justice Stephen Breyer of the court’s dissenting liberal wing asserted the ruling could prevent bail hearings for immigrants with even minor criminal records. This could cause “serious harm to the principles for which American law has long stood.”

“[The immigrants] may have established families and put down roots in a community,” Breyer said. “These aliens may then be detained for months, sometimes years, without the possibility of release.”

Tuesday’s ruling hands a victory to the Trump Administration, which last week sought tougher immigration policies. Last September, the administration proposed a rule that would make immigrants who use public benefits ineligible for green cards or to get admitted to the U.S.

Write to Hillary Leung at hillary.leung@time.com.