The US has already acknowledged Kilmar Abrego Garcia - a Salvadoran migrant who lived in the US legally with a work permit - was deported in error as part of three planeloads of migrants flown out in March over alleged ties to violent gangs.
But the administration has argued it has no legal authority to bring him back to the country, though Abrego Garcia's lawyers dispute that.
"They put him there, they can bring him back," said Andrew Rossman, a lawyer at law firm Quinn Emanuel that joined Abrego Garcia's legal team on Friday.
After questioning government lawyers, US District Judge Paula Xinis ruled at a Greenbelt, Maryland, hearing that the government must take steps to bring him back to the United States by April 7.
White House press secretary Karoline Leavitt said Xinis should contact President Nayib Bukele of El Salvador "because we are unaware of the judge having jurisdiction or authority over the country of El Salvador".
In a court filing on Saturday, the US Justice Department called the judge's order "indefensible" and urged an appeals court to immediately pause the ruling.
The United States said Abrego Garcia "has no legal right or basis to be in the United States at all" and "the public interest obviously disfavours his return, let alone a slapdash one conducted as the result of judicial fiat".
At the hearing on Friday, Abrego Garcia's lawyer Simon Sandoval-Moshenberg told the judge that there was no legal basis for the deportation.
"The public interest lies in the government following the law," Moshenberg said.
Erez Reuveni, a lawyer for the government, conceded that Abrego Garcia should not have been removed.
In an unusual exchange, Xinis grilled Reuveni on why the US could not get Abrego Garcia back - to which Reuveni said he had asked US government officials that question without getting a satisfactory answer himself.
The case is the latest flashpoint in the Trump administration's crackdown on immigration, which has raised constitutional questions and drawn the rebuke of a judge in Washington who is weighing whether US officials violated a court order temporarily blocking the deportation of alleged Venezuelan gang members under an 18th-century law.
Trump on March 15 invoked the 1798 Alien Enemies Act to rapidly deport alleged members of the Venezuelan gang Tren de Aragua.
The administration said it sent two flights to El Salvador that day carrying deportees processed under the rarely used wartime statute and a third flight carrying people deported under other rules.
Abrego Garcia was wrongfully placed on the third flight despite an 2019 judicial order granting him protection from deportation, a US immigration official has said in a court filing.