Some Guantanamo detainees will neither be tried nor released
A federal judge has ruled that the US government can detain terror suspects indefinitely, if they helped plan or carry out the 9/11 attacks.
Detainees who "substantially support" the Taliban or al-Qaeda but are not members cannot be held indefinitely, however, the judge decided.
Judge John Bates based his ruling on the authority granted to the president by Congress in 2002.
US President Barack Obama has pledged to close the prison at Guantanamo Bay.
But Congress has blocked funding for the closure of the camp until the White House decides what to do with its inmates.
Many members of Congress are opposed to the transfer of any detainees onto US soil.
The White House is currently deciding which detainees can be tried, which can be released, and which can be neither tried nor released.
It has previously indicated that between 50 and 100 detainees cannot be tried because of a lack of admissible evidence, but are deemed too dangerous to be released.
In his opinion, Judge Bates ruled that the president "has the authority to detain persons that the president determines planned, authorised, committed or aided the terrorist attacks that occurred on 11 September 2001, and persons who harboured those responsible for those attacks".
"The president also has the authority to detain persons who are or were part of Taliban or al-Qaeda forces or associated forces that are engaged in hostilities against the United States or its coalition partners, including any person who has committed (i.e., directly participated in) a belligerent act in aid of such enemy armed forces," he added.
But he could "find no authority in domestic law or the law of war, nor can the government point to any, to justify the concept of 'support' as a valid ground for detention".
Last week, President Obama announced that he would restart the military tribunals used by the Bush administration to try some of the terror suspects held at Guantanamo Bay.
Mr Obama changed the rules of the tribunals, adding some protections for detainees, but his decision still angered civil liberties campaigners, who want the detainees to be tried in regular US courts.
The president is to make a speech on Thursday defending his detainee policies.