Elite troops in Niger thwarted an "attempted coup" early Wednesday, a security source said, just two days before the historic inauguration of Mohamed Bazoum as president of the chronically unstable Sahel nation.
Residents earlier reported hearing gunfire in the middle of the night near the presidency in the capital Niamey.
"There were some arrests among a few members of the army who are behind this attempted coup," said the source, speaking on condition of anonymity.
"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 4am.
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.
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 ($55.1 million).
On March 8, Issoufou, the outgoing president, was awarded the coveted Ibrahim Prize -- Africa's top prize for leadership.