The Supreme Court on Tuesday handed the Trump administration a victory in its battle to clamp down on illegal immigration by making it easier to detain immigrants with criminal records.

The ruling that federal immigration authorities can detain immigrants awaiting deportation anytime after they have been released from prison on criminal charges represents a victory for President Trump.

In the case before the justices, a group of mostly green card holders argued that unless immigrants were picked up immediately after finishing their prison sentence, they should get a hearing to argue for their release while deportation proceedings go forward. But in the 5-4 decision on Tuesday, the Supreme Court ruled against them, deciding that federal immigration officials can detain noncitizens at any time after their release from local or state custody. The court also ruled the government maintains broad discretion to decide who would represent a danger to the community in deciding who to release or detain.

BORDER PATROL UNION LEADER: CONGRESS IS WRONG, NATIONAL EMERGENCY ON THE BORDER IS REAL

During oral arguments in October the Trump administration argued that given the limited money and manpower available, it was nearly impossible for the federal government to immediately detain every immigrant upon their release from custody.

Associate Justice Samuel Alito wrote the majority opinion, stating that “neither the statute’s text nor its structure” supported the immigrants’ argument. The court’s conservative justices sided with the Trump administration, which argued as the Obama administration did, against hearings for those convicted of crimes and affected by the law.

The case before the justices involved a class-action lawsuit brought by non-citizens in California and a similar class-action lawsuit brought in the state of Washington. One of the lead plaintiffs, Mony Preap, has been a lawful permanent resident of the United States since 1981 and has two convictions for possession of marijuana. He was released from prison in 2006 but was not taken into immigration custody until 2013.

CLICK HERE TO GET THE FOX NEWS APP

Preap won in lower courts, and the government was ordered to provide him and other class members a bond hearing. Preap has since won his deportation case.

The ruling was the first in the court’s current term – which began in October – and the first for Associate Justice Brett Kavanaugh, who, along with Chief Justice John Roberts, wrote a concurring opinion. The court’s four more liberal justices dissented, and Justice Stephen Breyer took the unusual step of reading an oral dissent from the bench.

Fox News’ William Mears and the Associated Press contributed to this report.