President George W Bush has signed into law a bill that sets standards for the interrogation and prosecution of foreign terror suspects held by the US.
The law aims to enshrine defendants' human rights, but still restricts their right to challenge their detention.
It follows a Supreme Court ruling in June that military tribunals set up to prosecute detainees at Guantanamo Bay violated US and international law.
A US spokesman said preparations would now begin to try Guantanamo suspects.
At a ceremony in Washington, Mr Bush said it was a rare occasion when a president signed a law that he knew would save American lives.
"I have that privilege this morning," he said, calling the Military Commissions Act "one of the most important pieces of legislation in the war on terror".
The president said the Central Intelligence Agency's programme of questioning terror suspects had proved invaluable, and the new law would reinforce this.
The Military Commissions Act, he said, would allow the CIA "to continue to question terrorists and save lives", adding: "It complies with the spirit and letter of the US's international obligations."
The law also set out a system of special tribunals, which would give defendants a fair trial, Mr Bush said.
"These military commissions will provide a fair trial in which the accused are presumed innocent, have access to an attorney, and can hear all the evidence against them. These military commissions are lawful, they are fair, and they are necessary."
Among those the US hopes to try are Khalid Sheikh Mohammed, the alleged mastermind of the 11 September attacks.
Speaking earlier, White House spokesman Tony Snow predicted it would take a month or two to "get things moving towards a trial phase" for some of those held at the US detention centre in Guantanamo Bay, Cuba.
The legislation was passed by both houses of Congress in September after intense debate.
The bill forbids treatment of detainees that would constitute war crimes - such as torture, rape and biological experiments - but gives the president the authority to decide which other techniques interrogators can use.
Several hundred detainees are being held at Guantanamo Bay
At the tribunals, defendants will be allowed to see some - but not necessarily all - of the evidence against them. The law also bars non-US citizens from filing habeas corpus petitions challenging their detentions in federal court.
Civil liberties groups say the law does not guarantee detainees' rights, and legal challenges are to be expected.
The BBC's Jonathan Beale in Washington says that although the law says detainees cannot be subjected to inhumane or cruel treatment, it is not clear which interrogation techniques can still be used.
The US defence department has laid charges against 10 detainees and is preparing to charge about 65 more.
There are about 450 detainees at the Guantanamo Bay prison facility on Cuba, according to the Bush administration.