The US has released a dual American-Saudi citizen who was detained without trial for 13 months on suspicion of being a member of Islamic State group.
The American Civil Liberties Union (ACLU), which represented the man, confirmed he was freed on Sunday.
He was captured by Kurdish forces in Syria in September 2017 and then transferred to a US base in Iraq.
The man denied being an "enemy combatant", insisting he was in Syria to report on the country's civil war.
Initially, the US government blocked his access to a lawyer and the courts.
Despite not knowing him the ACLU filed a habeas corpus lawsuit on his behalf, demanding that the government justified his indefinite detention.
The government asked a judge to dismiss the case, arguing that the ACLU had no relationship with the man. But the judge criticised the government's position as "disingenuous at best" and ordered that a lawyer from the rights organisation be given unmonitored access to him.
The government fought the habeas corpus lawsuit by arguing it had the power to imprison the man without charge because he was an enemy combatant.
It said the evidence it had compiled showed the man joined IS during an initial visit to Syria in 2014; returned to the country in 2015 and attended an IS training camp, swearing loyalty to the leader of the jihadist group; and then worked for IS in various capacities until last year, when air strikes and an offensive by the US-backed Syrian Democratic Forces alliance forced him to flee.
When the man was captured at an SDF checkpoint on an active battlefield near territory controlled by IS, the government added, he was carrying a thumb drive that contained IS documents and manuals, more than $4,000 in cash, and a GPS device. He was also allegedly listed by name as a "fighter" in an IS document.
BREAKING: @ACLU confirms release of American unlawfully detained in Iraq. After repeated defeats in court--and unwilling to defend its dubious detention power--the US grants our client his liberty. John Doe is now a free man.https://t.co/ji5RIeh4RU @HinaShamsi @brettmaxkaufman— Jonathan Hafetz (@JonathanHafetz) October 29, 2018
The man contested the allegations and maintained that the government had to prove them in a trial if it wanted to continue holding him. He said he only went to Syria to be a journalist, was arrested by IS, and then agreed to work for the group to gain release from prison.
In response, the government sought to transfer the man to the custody of another country over his objection. But a federal court in Washington DC blocked the move - a ruling that was upheld at appeal in May.
The next month, the government announced its intention to release the man in Syria, which it said was consistent with its obligations under the laws of war. But it dropped the plan after the ACLU asked a court to block it.
The rights organisation said a settlement agreement led to the man being released on Sunday to an unspecified third country.
"This case demonstrates that the president cannot take away an American's liberty without due process, showing the continuing importance of judicial review," ACLU senior staff attorney Jonathan Hafetz said on Monday.
"This case also illustrates the critical role that the press plays as a check against government abuse of authority. Without the original revelation by journalists about this American's incommunicado and illegal detention, he might never have gotten his day in court at all."