WASHINGTON – The Supreme Court, deeply divided along ideological lines, handed the Trump administration a victory Tuesday by making it easier to detain noncitizens with criminal records during deportation proceedings.

The justices reversed a lower-court decision that permitted such detention only if federal agents picked up the noncitizen immediately after being released from custody, rather than months or years later. Immigration rights advocates had argued that such detentions must occur within 24 hours.

The 5-4 ruling was a victory for the court's conservative justices, who complained during oral argument in October that the government cannot detain every immigrant immediately – particularly when money and manpower are limited, and state and local "sanctuary city" governments may be opposed.

It was the first decision of the court's term, which began in October, that resulted in a straight conservative-liberal breakdown. Associate Justice Samuel Alito wrote the opinion and was joined by four conservatives. Associate Justice Stephen Breyer issued a stinging dissent on behalf of the liberals.

Alito sought to make clear that the ruling was not aimed at "extreme" examples of people picked up years after they have finished serving time, when they are leading law-abiding lives and have blended into their communities. Such immigrants can file individual challenges on constitutional grounds, he said.

But it would be unreasonable, Alito said, for homeland security agents to "turn into pumpkins" at midnight on the day noncitizens are released from criminal custody, forever unable to detain them without offering a bond hearing. Various deadlines suggested by immigration rights advocates, he said, "are taken out of thin air."

Breyer delivered his dissent from the bench, which is rarely done, to warn that the decision gives too much power to the federal government.

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

Cecillia Wang, deputy legal director at the American Civil Liberties Union, which represented immigrants challenging detention without bail, decried "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."

Immigration is an issue that frequently divides the high court. In February 2018, the justices ruled 5-3 that detained non-citizens lack the right to periodic bond hearings. In April, they ruled 5-4 that a law subjecting non-citizens to deportation for crimes of violence was unconstitutionally vague, with Associate Justice Neil Gorsuch joining a liberal majority.

And in June, the conservative majority in a 5-4 ruling upheld President Donald Trump's ban on travel from five predominantly Muslim countries.

The class action case against mandatory detention was brought by two lawful permanent residents who were taken into custody years after their release from prison. Both eventually received bond hearings and were allowed to stay in the country.

The Trump administration appealed lower court rulings in favor of the immigrants, and the Supreme Court agreed to hear the case last spring, before Associate Justice Anthony Kennedy retired and was replaced by Brett Kavanaugh.

During oral argument, Wang said the law requires the government to detain immigrants on the same day their prison terms are completed. Several conservative justices said that was often impossible.

"It's not reasonable if they don't have enough people to do it," Chief Justice John Roberts said. "I don't know what's reasonable in this situation. A month?"

Kavanaugh said Congress sought "harshness" in 1996 to crack down on illegal immigration and would not have wanted limits on the ability to detain people with criminal records.

"Congress, wisely or not, thought that this class of aliens was dangerous, and they should not be trusted," Alito added at the time.

But the court's four liberal justices said the government shouldn't be allowed to pick up undocumented immigrants years or even decades after they have reintegrated into their communities, particularly without a bond hearing.

"There's a constitutional problem in a country which gives every triple ax murderer a bail hearing, but these people don't," Breyer said.

Associate Justice Sonia Sotomayor said the number of illegal immigrants who are recidivists pales compared to a "huge class of people who are being held, where no one would consider them dangerous."

More:President Trump bets big on Supreme Court to uphold controversial policies after lower court losses

More:Supreme Court seems divided on Virginia's use of race to draw election districts

More:Supreme Court turns down Trump request to restart asylum ban