About 600 so-called enemy combatants are held at Bagram air base
A US judge has ruled that foreign suspects held by the US in Afghanistan have the right to challenge their detention in US civilian courts.
Judge John Bates denied the motion by the US government to withhold the right to three detainees at Bagram air base.
The US Supreme Court ruled last year that detainees at Guantanamo had such a right. The justice department later said those held at Bagram did not.
Judge Bates said the cases were essentially the same.
The three detainees have been held at the US military prison at Bagram for at least six years after having been captured outside Afghanistan.
Judge Bates' ruling now allows them to challenge their detention in the US justice system.
The three detainees are Fadi al Maqaleh and Amin al Bakri from Yemen and Redha al-Najar from Tunisia.
A fourth detainee, Haji Wazir, who had also brought a lawsuit seeking his release is an Afghan citizen.
Judge Bates reserved judgement on his case, saying the implication that he could be released could create "friction with the host country".
"Bagram detainees who are not Afghan citizens, who were not captured in Afghanistan and who have been held for an unreasonable amount of time - here over six years - without adequate process" have the legal right to challenge their detention in US courts, Judge Bates said in his 53-page opinion.
The justice department said it was reviewing the ruling.
'Great day for justice'
The ruling is a rebuff to the Obama administration, says the BBC's Adam Brookes in Washington.
It is not definitive, says our correspondent. Legal proceedings will continue for some time.
A lawyer representing one of the detainees said it was "a great day for American justice".
"Today, a US federal judge ruled that our government cannot simply kidnap people and hold them beyond the law," lawyer Ramzi Kassem was quoted as saying by the Washington Post.
About 600 so-called enemy combatants are held at the US prison at Bagram air base.