By Ibrahima Sylla
NOUAKCHOTT, Aug 3 (Reuters) - Mauritania's army said on Wednesday it had seized power to end the "totalitarian" regime of President Maaouya Ould Sid'Ahmed Taya, who is out of the country, and planned to rule for up to two years.
Hundreds of people took to the streets to shout and honk car horns in celebration at the coup against Taya, in power for more than two decades, but his supporters denounced the coup.
"There was no democracy here ... We have been freed from a dictatorship," said one middle-aged man who gave his name as Bilal as he watched the celebrations in the capital.
The African Union and United Nations Secretary-General Kofi Annan both condemned the seizure of power by force.
Mauritania, which straddles black and Arab Africa and hopes to start pumping oil next year, has witnessed a series of uprisings and attempted military coups in recent years.
Taya, who first seized power in a 1984 putsch, has angered many Arabs in the country by shifting support from former Iraqi president Saddam Hussein to Israel and Washington in the 1990s.
Convoys of cars with people hanging out of them shouting "Praise be to God" and making victory signs paraded down one of the main sand-blanketed avenues in Nouakchott.
"The armed forces and security forces have unanimously decided to put a definitive end to the totalitarian activities of the defunct regime under which our people have suffered so much over recent years," said a statement signed by a "Military Council for Justice and Democracy".
"This council pledges before the Mauritanian people to create favourable circumstances for an open and transparent democracy," said the statement, broadcast on state media.
Hundreds of people gathered at a mosque near the capital's main prison, hoping relatives would be freed, especially suspected Islamist militants involved in a June 2003 army uprising.
Taya, who was in Saudi Arabia for King Fahd's funeral on Tuesday, landed in Niger's capital hours after news of troop movements in Nouakchott. His PRDS party denounced the coup.
Witnesses said that green-bereted members of Taya's guard had taken over state television and radio. Gunfire rang out briefly near the presidency building and the airport was closed.
An opposition leader and a military source said they believed the head of the presidential guard, Colonel Mohamed Ould Abdel-Aziz, was involved in the coup.
The source said senior military officers had been arrested, including the head of the army, national guard, paramilitary police and elite parachute regiment.
Mauritania, an Islamic Republic, is one of only three Arab League member states that have diplomatic ties with Israel.
It is also considered one of the most repressive countries in the region towards Islamist movements.
Scores of Islamic opposition activists have been arrested since April and accused of colluding with Algeria's Salafist Group for Preaching and Combat, an al Qaeda ally.
Troops nearly toppled Taya in 2003 during two days of fighting in Nouakchott before loyalists prevailed. The government says it foiled two coup bids in 2004.
Earlier, shops in Nouakchott shut in a hurry and taxis refused to pick up people trying to leave the city centre.
"I heard a burst of gunfire near the presidency. I saw scared people running away. Civil servants have all left their offices," a Reuters witness in the capital said.
"All the army is in the streets. It's blocking the roads to the presidency and the main routes through town," said a civil servant who lives near the presidency building.
A witness said the border with Senegal was closed.
The United States has been sending officers to train soldiers in Mauritania and other countries in the region to combat militants thought to be operating in the Sahara.
The U.S. European Command, which overseas U.S. military operations in 91 countries and territories in Europe and most of Africa, said it was monitoring the situation.