WASHINGTON (CNN) -- Suspected terrorists and foreign fighters held by the U.S. military at Guantanamo Bay, Cuba, have the right to challenge their detention in federal court, the Supreme Court ruled Thursday.

A prefabricated court complex has been erected at Guantanamo Bay, Cuba, to try terrorism suspects.

The decision marks another legal blow to the Bush administration's war on terrorism policies.

The 5-4 vote reflects the divide over how much legal autonomy the U.S. military should have to prosecute about 270 prisoners, some of whom have been held for more than six years without charges. Fourteen of them are alleged to be top al Qaeda figures.

Writing for the majority, Justice Anthony Kennedy said, "the laws and Constitution are designed to survive, and remain in force, in extraordinary times. Liberty and security can be reconciled; and in our system reconciled within the framework of the law."

Kennedy, the court's swing vote, was supported by Justices John Paul Stevens, David Souter, Ruth Bader Ginsburg and Stephen Breyer, generally considered the liberal contingent.

At issue was the rights of detainees to contest their imprisonment and challenge the rules set up to try them. Watch how the 5-4 ruling is a major blow for the Bush administration »

A congressional law passed in 2006 would limit court jurisdiction to hear so-called habeas corpus challenges to detention. It is a legal question the justices have tackled three times since 2004, including Thursday's ruling.

Each time, the justices have ruled against the government's claim that it has the authority to hold people it considers "enemy combatants."

Preliminary hearings have begun in Guantanamo for some of the accused. A military panel this month arraigned five suspected senior al Qaeda detainees, including the alleged mastermind of the September 11 attacks, Khalid Sheikh Mohammed, who was transferred to the prison camp in 2006.

The Bush administration has urged the high court not to get involved in the broader appeals, saying the federal judiciary has no authority to hear such matters.

Four justices agreed. In a sharp dissent, read in part from the bench, Justice Antonin Scalia said the majority "warps our Constitution."

The "nation will live to regret what the court has done today," Scalia said.

He was supported by Chief Justice John Roberts and Justices Clarence Thomas and Samuel Alito.

President Bush, who is traveling in Europe, said he disagreed with the Guantanamo ruling but promised to abide by it.

"Congress and the administration worked very carefully on a piece of legislation that set the appropriate procedures in place as to how to deal with the detainees," he said. "We'll study this opinion, and we'll do so with this in mind to determine whether or not additional legislation might be appropriate so that we can safely say, truly say to the American people, 'we are doing everything we can to protect you.' "

The Pentagon declined to comment, and the Justice Department said it was reviewing the decision and was expected to comment later Thursday.

House Speaker Nancy Pelosi, D-California, welcomed the ruling, saying the Supreme Court upheld the Constitution.

"I have long been an advocate of closing Guantanamo, so I would hope this is in furtherance of taking that action," Pelosi said.

The appeals involve noncitizens. Sixteen lawsuits filed on behalf of about 200 prisoners were put on hold pending a ruling last year by a federal appeals court upholding the government's right to detain and prosecute suspected terrorists and war criminals.

An attorney for one of the detainees, Salim Ahmed Hamdan -- Osama bin Laden's alleged driver and bodyguard -- said he would file an appeal asking that charges be dropped against the Yemeni native.

"The clearest immediate impact of this ruling is to remove the remaining barriers for closing Guantanamo Bay. It means, in legal terms, Guantanamo Bay is no different than Kansas," attorney Charles Swift said.

Now the ruling has been issued, a flood of similar appeals can be expected.

The lead plaintiffs are Lakhdar Boumediene, a Bosnian, and Fawzi al-Odah of Kuwait. They question the constitutionality of the Military Commissions Act, passed by Congress in October 2006. The law addresses how suspected foreign terrorists and fighters can be tried and sentenced under U.S. military law.

Under the system, those facing trial would have a limited right to appeal any conviction, reducing the jurisdiction of federal courts.

The suspects also must prove to a three-person panel of military officers they are not a terror risk. But defendants would have access to evidence normally given to a jury, and CIA agents were given more guidance in how far they can go in interrogating prisoners.

The law was a direct response to a June 2006 Supreme Court ruling striking down the Bush administration's plan to try detainees before military commissions.

In 2004, the justices also affirmed the right of prisoners to challenge their detention in federal court. Congress and the administration have sought to restrict such access.

The Justice Department wanted the high court to pass on these appeals, at least until the first wave of tribunals had a chance to work. Administration officials also argued the prisoners have plenty of legal safeguards.

The White House has said it is considering whether to close the Guantanamo prison, suggesting some high-level al Qaeda detainees could be transferred to the federal prison in Leavenworth, Kansas, and to a military brig in North Charleston, South Carolina.

Most of the dozens of pending cases have been handled in the U.S. Court of Appeals in Washington, which in February 2007 upheld the Military Commissions Act's provision stripping courts of jurisdiction to hear "habeas" challenges to the prisoners' confinement.

But a three-judge panel of the same circuit expressed concern about why the U.S. military continues to limit attorney access to the Guantanamo men.

The detainees' legal team alleges the government is unfairly restricting access to potentially exculpatory evidence, including documents they may not know exist before pretrial hearings.

Legal and terrorism analysts said the issues presented in these latest sets of appeals are unlike those the justices have delved into previously.

"The difference in this case is that they have a congressional enactment cutting back on habeas corpus that they have to wrestle with," said Edward Lazarus, a leading appellate attorney and author of a book on the high court, "Closed Chambers: The Rise, Fall, and Future of the Modern Supreme Court."

"And that, from a constitutional point of view, is really a different question."

In a separate decision, the court refused to intervene in the case of two American citizens convicted in Iraqi courts but held by the U.S. military.

The high court rejected lawyers' arguments that Mohammad Munaf and Shawqi Ahmad Omar should be released, saying that U.S. courts are not allowed to intervene in foreign courts.

All About U.S. Supreme Court • Guantanamo Bay • Terrorism