President George W Bush cannot order the indefinite military detention of a Qatari man accused of being an al-Qaeda agent, a US appeals court has ruled.
Mr Marri was arrested three months after the 11 September attacks
Ali Saleh Kahlah al-Marri, the only person being held on US soil as an "enemy combatant", was seized three months after the 9/11 terror attacks.
He has been held without charge in a navy prison for almost four years.
The ruling is seen as a setback for the Bush administration over its policies on the detention of terror suspects.
Mr Marri, who entered the US legally on 10 September 2001 to study at a US university, was arrested in December that year following investigations into the 9/11 attacks.
A civilian court in Illinois charged him with offences including credit card fraud and lying to FBI agents.
While the criminal proceedings were progressing, he was transferred on the orders of the president to the military authorities, who have held him in South Carolina since 2003.
However, the appeals court in Virginia ruled on Monday that Mr Marri has habeas corpus rights - entitling him to challenge his detention in court - and has ordered his release from military custody.
"To sanction such presidential authority to order the military to seize and indefinitely detain civilians, even if the president calls them 'enemy combatants', would have disastrous consequences for the constitution - and the country," the court opinion said.
This does not mean Mr Marri must be set free though, the judges stated, saying he could face civilian criminal charges or be deported.
"Like others accused of terrorist activity in this country, from the Oklahoma City bombers to the surviving conspirator of the September 11 attacks, al-Marri can be returned to civilian prosecutors, tried on criminal charges, and, if convicted, punished severely," the court ruled.
"But the government cannot subject al-Marri to indefinite military detention."
Bin Laden 'link'
The government had urged the court to reject Mr Marri's case on the grounds that the Military Commissions Act of 2006, which strips detainees in Guantanamo Bay, Cuba, of their habeas corpus rights, applied also to him.
Under that law, detainees must be judged by a military tribunal before they can challenge their detention in a civil court.
The justice department claims Mr Marri helped settle al-Qaeda operatives who were planning attacks in the US.
It also accuses him of training at an al-Qaeda camp and meeting the group's chief, Osama Bin Laden, and Khalid Sheikh Mohammed, the alleged mastermind of the 9/11 attacks.
It is not yet clear whether the appeal court's decision will have implications for detainees held at Guantanamo Bay.
It comes a week after military judges threw out charges against two of those detained there because military authorities had failed to designate the men as "unlawful" enemy combatants.