Niamey (AFP) -
Niger thwarted an 'attempted coup' on Wednesday, the government said, two days before the historic inauguration of Mohamed Bazoum as president of the unstable Sahel nation.
Residents in the capital Niamey earlier reported hearing gunfire in the middle of the night in the district where the presidency is located.
A government statement said 'an attempted coup' had been blocked, condemning what it called a 'cowardly and regressive act which sought to threaten democracy and the state of law.'
An investigation has been launched and 'several people connected with this attempted coup have been detained and others are being actively sought,' it said, without giving further details.
'The situation is totally under control,' the statement added, calling on the public to 'carry on with normal life.'
A security source, speaking on condition of anonymity, said 'there were some arrests among a few members of the army' who had been behind the coup bid.
'The Presidential Guard retaliated, preventing this group of soldiers from approaching the presidential palace,' the source said.
A resident of Niamey's Plateau district, which includes the president's official residence and offices, told AFP: 'It was around 3 am, we heard shots from heavy and light weapons and it lasted 15 minutes before stopping, followed by shots from light weapons.'
'The gunfire lasted about 20 minutes,' another resident said.
A third resident spoke of 'intense shooting, with heavy and light weapons'.
Online newspaper actuniger.com reported that calm had returned by around 4 am.
In short video clips posted on social networks, only several seconds in length, sporadic bursts of gunfire could be heard in the pitch dark.
It was not immediately possible to verify the videos independently.
The US embassy said it was suspending consular services until further notice and advised its employees not to come to work, and the French embassy similarly urged French nationals to stay at home.
The alleged coup comes ahead of Bazoum's inauguration on Friday -- the first elected transition in Niger's history since independence from France in 1960.
Bazoum is a former interior minister and right-hand man of outgoing president Mahamadou Issoufou, who is voluntarily stepping down after two five-year terms, a move that has been warmly praised by France and others.
Bazoum's victory in the second round of elections on February 2 was confirmed by the constitutional court this month.
The runner-up, former president Mahamane Ousmane, contested the results, claiming that he was the real winner.
Ousmane had called for 'peaceful marches' across the country, but authorities banned a planned opposition protest Wednesday in Niamey the day before.
- Troubled nation -
Niger is the poorest country in the world, according to the benchmark of the UN's 189-nation Human Development Index (HDI).
It has suffered four coups in its history, most recently a February 2010 putsch which toppled then president Mamadou Tandja.
The Sahel country has also been struck by repeated jihadist attacks, from insurgents who have advanced from Mali in the west and Nigeria in the southeast.
More than 300 people have been killed in three attacks in the west since the start of the year.
In the most recent of these, 141 members of the Tuareg community were massacred on March 21 in Tahoua, a vast desert region abutting Mali.
Bazoum has ruled out any talks with the insurgents.
Niger's armed forces are poorly equipped and trained, and number just 25,000 in a country twice the size of Texas.
The plan is to double this to 50,000 men within five years, but funding is key.
Last year, violent protests broke out over a military procurement scandal officially estimated to have cost nearly 32.6 billion CFA francs (49.7 million euros/$55.1 million).
On March 8, Issoufou, the outgoing president, was awarded the coveted Ibrahim Prize -- Africa's top prize for leadership.