A Saudi-American dual national held by the US military in Iraq as a "foreign fighter" for 13 months has been freed, his lawyers have said, after his case tested the Trump administration's legal detention powers.
The man, never identified in court filings but named by The New York Times as Abdulrahman Ahmad Alsheikh, was captured last year in Syria while allegedly fighting for ISIS and handed over to American forces.
In a series of key rulings in US federal court in Washington against the Justice Department, the Pentagon was forced to grant the man legal representation by the American Civil Liberties Union, and then was blocked from simply handing him over to Saudi Arabia when he wanted to return to the United States.
Rather than bring him back to the US and try him on charges of abetting a designated terrorist group, however, the Justice Department said in June it planned to release him back into northern Syria where he was captured with $4,210 and a cellphone.
That move was also blocked after his lawyers argued it would leave him unprotected in a battlefield region and equaled a "death sentence".
At each step of the case, the ACLU demanded the government charge or release the man in accordance with his habeas corpus rights under the US Constitution, testing whether the Trump administration was willing to bring back an alleged American fighter for ISIS and put him on trial in US courts.
Such a trial could have raised other fundamental issues, such as the legality of US military action in Syria.
"My case has shown the worst and the best of my country," the man, who was only identified as John Doe in court filings, said in a statement.
"When I fled violence in Syria, I never imagined that my country would deny me access to a lawyer for nearly four months, and imprison me without charge in solitary confinement for over a year.
"No one, no matter what they are suspected of, should be treated the way my government treated me. Once I got the chance to stand up for my rights, the constitution and the courts protected me," he added.
According to the Times, he was released in Bahrain after reaching a confidential settlement with the US government.
Government attorneys never presented evidence that the man was an ISIS members, which he denies, and his reason for having been in Syria remains unexplained.
He reportedly did not give up his US citizenship, but his passport was cancelled.
"Doe has requested time and privacy to rebuild his life. He also wishes to remain anonymous for the same reason," the ACLU said.
Lawyer Jonathan Hafetz said the government "did all it could" to avoid proving its detention of the man was lawful.
"This case shows the enduring importance of the courts in safeguarding the rights of Americans against government overreach," Mr Hafetz added.