Bates said his ruling only applied to the part of the legal action specifically seeking the release of the Bagram detainees and did not affect their legal challenge regarding conditions at the base.

Afghan held

The case centred on two Yemenis, a Tunisian and also an Afghan national who have all been held at Bagram for at least six years.

Bates said the three foreign detainees had the legal right to challenge their detention but postponed a decision on Haji Wazir, the Afghan national.

Releasing him could create "practical obstacles in the form of friction with the host country," Bates wrote.

He ordered Wazir and the government to file memos addressing those issues.

Obama has ordered the Guantanamo prison, which has been widely criticised by human rights groups, to be closed within one year.