NEW YORK: Hundreds of Venezuelans deported from the United States to El Salvador under an 18th century wartime law must be given the chance to challenge their detentions, and the Trump administration must facilitate the legal challenges, a U.S. judge ruled on Wednesday.

U.S. District Judge James Boasberg stopped short of expressly ordering the Trump administration to bring the hundreds of Venezuelan migrants currently being held in a mega-prison in El Salvador back to the United States.

The judge gave the Trump administration one week to detail how it would facilitate the deportees' filing of legal challenges.

In his ruling, Boasberg wrote that the individuals were deported without adequate notice or the right to contest their removals.

“That process - which was improperly withheld - must now be afforded to them,“ Boasberg wrote. “Absent this relief, the government could snatch anyone off the street, turn him over to a foreign country, and then effectively foreclose any corrective course of action.”

It was not immediately clear how the migrants would file the legal challenges, known as habeas corpus petitions, from within El Salvador's Terrorism Confinement Center.

The Venezuelans were deported in March after President Donald Trump, a Republican, invoked the 1798 Alien Enemies Act to swiftly deport alleged members of the Tren de Aragua gang without going through normal immigration procedures.

Boasberg's Wednesday ruling is the first to address the fate of these detainees.

Neither the White House nor the Justice Department immediately responded to requests for comment.

Family members of many of the Venezuelans deported on March 15 and their lawyers deny the migrants had any gang ties, and say they were not given a chance to contest the Trump administration's allegations in court.

The Trump administration is paying President Nayib Bukele's government $6 million to hold them.

The U.S. Supreme Court in April held that migrants must be allowed to challenge their removals under the Alien Enemies Act. Courts around the country have since barred the Trump administration from further deportations of alleged Tren de Aragua members under the law.

But those rulings only applied to Venezuelans still in the U.S. facing possible deportation under the law.

Crackdown on Immigration

The ruling by Boasberg, an appointee of Democratic President Barack Obama, is the latest judicial ruling against Trump's aggressive immigration policy. But the Republican president has also scored major wins from the U.S. Supreme Court, which has backed his hardline approach in some cases while also signaling some reservations with how he is carrying out his agenda.

Trump campaigned for his second term on a pledge to step up deportations.

Trump, who has accused federal judges of stifling his agenda, called for Boasberg's impeachment after the judge in March granted a request by lawyers for the Venezuelan migrants to temporarily block their deportations.

Trump's comment prompted a rebuke from U.S. Chief Justice John Roberts, who said appeals, not impeachments, were the proper way to handle disagreements with judicial rulings.

At the time of Boasberg's March ruling, planes carrying the migrants had already taken off from the U.S.

The judge ordered the administration to return the migrants. When officials did not, Boasberg opened an inquiry into whether anyone should be held in contempt for disobeying his order.

The judge's probe is on hold while the Trump administration appeals.

In Wednesday's ruling, Boasberg cited the Supreme Court's ruling in a separate case upholding a lower court's order for the administration to facilitate the return of Kilmar Abrego Garcia, a Salvadoran migrant living in Maryland who was deported to El Salvador despite an earlier court ruling that he not be sent there.

The Supreme Court, however, struck down an order by the judge in that case that the government “effectuate” Abrego Garcia’s return, citing the deference courts must give to the government on foreign policy matters.

Boasberg said his decision to allow the Trump administration propose a procedure for allowing the Venezuelans to file legal challenges balanced the executive branch's authority over foreign affairs with the migrants' constitutional rights.