Guantanamo Bay prisoners have the right to go before US federal judges to challenge their years-long detention, the Supreme Court ruled today in a stinging setback for the Bush administration.

Download the new Independent Premium app Sharing the full story, not just the headlines

By a 5-4 vote, the high court overturned a ruling that upheld a law President George Bush pushed through the Republican-led Congress in 2006 that took away the habeas corpus rights of the terrorism suspects to seek full judicial review of their detention.

"We hold these petitioners do have the habeas corpus privilege," Justice Anthony Kennedy wrote for the court majority in the 70-page opinion, portions of which he read from the bench.

Habeas corpus is a long-standing legal right that allows prisoners to challenge their confinement by the government. Kennedy said Congress had failed to create an adequate alternative for the prisoners held at the US military base in Cuba to contest their detention.

The 2006 law allowed for a limited review by a US appeals court in Washington of the military's designation of the prisoners as "enemy combatants." It took away their right to a hearing before a US district court judge to challenge their confinement.

Kennedy said the court's ruling did not address whether Bush has the authority to detain the prisoners. He said this and other questions on the legality of their detention must be resolved by the federal judges.

Amnesty International, which has campaigned for the prisoners' rights, welcomed the ruling. "The Supreme Court did the right thing. Everyone has the right to challenge why they're being thrown in prison, to hear the charges against them and to answer to that," Daila Hashad, Amnesty's domestic human rights programme director, said.

"It's a real shame that in the 21st Century, we've taken such a step backward in the Bush Administration, to say we have the right to throw someone in jail and throw away the key - but no longer."

The majority consisted of the court's four liberals - Justices John Paul Stevens, David Souter, Ruth Bader Ginsburg and Stephen Breyer, plus the moderate conservative Kennedy, who often casts the decisive vote.

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

The four conservative dissenters were Chief Justice John Roberts and Justice Samuel Alito, both appointed by Bush, and Justices Antonin Scalia and Clarence Thomas.

The Guantanamo prison opened in January 2002 after the administration launched what Bush called a "war on terrorism" in response to the 11 September attacks. The administration has argued the naval base, on land leased from Cuba, is outside US territory so constitutional protections do not apply to the detainees.

There now are about 270 prisoners at Guantanamo. Most have been held for years without being charged and many have complained of abuse.