A federal judge in Washington blocked the government on Thursday from immediately transferring to another country an American citizen detained by the U.S. military in Iraq.

The ruling from U.S. District Judge Tanya S. Chutkan temporarily halting the planned transfer to an unnamed country came within a half-hour of an 8 p.m. deadline, at which point the government would have been free to make the handoff.

Attorneys for the man, held without charges for seven months, had challenged the move, saying the U.S. government lacks the legal authority to transfer him to a third country.

The Justice Department appealed Friday to the U.S. Court of Appeals for the D.C. Circuit.

“Petitioner’s motion for a preliminary injunction is hereby granted,” Chutkan wrote in a one-paragraph order, enjoining the Defense Department “from transferring petitioner from U.S. custody.”

The order said Chutkan would issue a public, redacted opinion after consulting with the detainee and the government’s attorneys on classified or sensitive information to be withheld.

The U.S. military has held the unidentified man as a suspected member of the Islamic State since he was turned over to American forces on Sept. 14 after he was captured in Syria at a rebel Syrian Democratic Forces checkpoint and declared his U.S. citizenship. The man, who grew up in Saudi Arabia and is a dual citizen, was questioned for U.S. intelligence purposes, but American officials have said they lack admissible evidence to charge him with a crime.

At a hearing Thursday morning, the man’s attorney, Jonathan Hafetz of the American Civil Liberties Union, said the government must either “charge him with a crime or release him. . . . He is fighting for his freedom.”

Justice Department attorney James Burnham said handing off the man would end the U.S. government’s control over the detainee.

“It’s not release,” Chutkan responded, “if you’re simply giving him over to another jailer.”

The ACLU asked the court to temporarily block the transfer and require the U.S. government to cite a specific, “positive legal authority” to move an American citizen prisoner to a third country beyond an assertion that the other country has a “strong interest” in the citizen, according to court papers filed Wednesday.

In the government’s filings, a State Department official called the quick transfer “vital diplomatically to the United States” now that an unnamed third country has invoked its “sovereign interest” to accept the detainee and formally confirmed he would not face torture, a pledge required by U.S. law in cases of involuntary transfer.

During the hearing Thursday, Chutkan acknowledged the seriousness of the allegations against the man but seemed skeptical of the government’s stated justification, noting there was no evidence that he had committed a crime in the country that would receive him.

“What you’re giving me right now is not a lot more than what you gave me in January,” she said of the earlier hearing challenging the possible transfer. Chutkan then closed the courtroom to the public to discuss elements of the case that remain sealed.

The hearing Thursday is the latest development in a case that has tested whether U.S. citizens captured on a battlefield as suspected Islamic State fighters have the right to challenge their detentions.

The government has said in court filings that the man was born in the United States but raised in Saudi Arabia. He attended college and studied electrical engineering in Louisiana, is married and has a 3-year-old daughter whom he tried to register as an American citizen on two trips to the United States in 2014, according to court filings.

The D.C. Circuit was already weighing an earlier ruling from the same judge in which she required the government to give 72 hours notice before the suspect’s transfer. That notice became public this week and the three-day window to intervene closed at 8 p.m. Thursday.