* Top appeals court upheld prison terms for 13 dissidents
* Human Rights Watch, Amnesty criticise ruling
* UN rights panel sees possible wrongful convictions
* Government says Bahraini courts are independent (Adds comment from U.N. Secretary-General)
By Rania El Gamal
DUBAI, Jan 8 (Reuters) - An appeals court ruling confirming prison terms for 13 protest leaders in Bahrain this week shows the Gulf Arab state's judicial system is flawed and unable to protect basic rights, international watchdog groups said.
Bahrain, a U.S. ally against Iran and home to the U.S. Fifth Fleet, has been in political ferment since a street revolt led by majority Shi'ite Muslims erupted in early 2011, part of a tide of unrest against autocratic rulers across the Arab world.
On Monday, Bahrain's highest appeals court upheld sentences for protest leaders ranging from five years in prison to life that were originally handed down by a military court in June 2011, a ruling that could kindle further unrest.
U.N. Secretary-General Ban Ki-moon said on Tuesday he deeply regretted the court's decision, describing the sentences as "harsh".
International bodies have repeatedly criticised the prosecutions and U.S. officials had called for acquittals to help restore calm and stability in the island monarchy.
"The mind-boggling verdicts in these cases did not mention a single recognisable criminal offence," said Joe Stork, deputy Middle East director for New York-based Human Rights Watch.
The verdicts had instead been based upon "speeches the defendants made, meetings they attended, and their calls for peaceful street protests in February and March 2011," he said in a statement.
"Bahrain's Cassation Court has proven its inability to protect the most basic rights guaranteed in Bahrain's constitution and the international treaties it has signed," he added.
The government says Bahrain's courts are independent, though the Sunni Muslim ruling Al Khalifa family holds senior cabinet portfolios including justice and key posts in the judiciary.
The Court of Cassation is headed by an Al Khalifa relative and King Hamad heads the Supreme Judicial Council.
In Geneva, U.N. human rights spokeswoman Cecile Pouilly said she regretted the convictions despite "conclusions of the Bahrain independent commission of inquiry and appeals by the international community concerning the judicial procedure and allegations of torture".
"These persons are political and human rights activists and we are concerned they may have been convicted wrongly for legitimate activities," Pouilly told a news briefing on Tuesday.
Widespread and excessive use of force, including confessions under torture, was detailed by the commission of international legal experts in November 2011, and they recommended measures to stop such practices.
"TOEING THE GOVERNMENT LINE"
Amnesty International said the ruling highlighted "flaws" in Bahrain's justice system and the defendants should be released.
"This unjust decision will confirm the view of many that the judiciary is more concerned about toeing the government's line than upholding the rule of law and the rights of all Bahrainis," said Hassiba Hadj Sahraoui, deputy director of London-based Amnesty's Middle East and North Africa programme.
The main charges the protest leaders faced were "forming a terrorist group with intent to overthrow the system of government", as well as collaboration with a foreign state - an allusion to Iran which Bahrain says fomented the unrest.
The men denied all charges saying they wanted only democratic reform. They also deny links to Iran and Tehran has also denied any involvement.
The government, backed by troops from Saudi Arabia and police from the United Arab Emirates, put down the uprising with martial law in March 2011. Thousands were arrested and military trials conducted.
Bahrain says it is now carrying out a range of political, legal, police, education, media and other reforms.
But opposition leaders have dismissed those plans as cosmetic and protests have continued, albeit on a reduced scale.
Police and demonstrators clash almost daily and each side blames the other for the violence and the absence of talks to end the conflict. (Additional reporting by Stephanie Nebehay in Geneva; Editing by Andrew Hammond and Mark Heinrich)