Niger President-elect Mohamed Bazoum will take over from President Mahamadou Issoufou. [Reuters]

A military unit tried to seize the presidential palace in Niger's capital Niamey overnight but it was pushed back by heavy gunfire and order has been restored, a senior Niger security source said yesterday, days before a handover of power.

The assailants, from a nearby airbase, fled after their attack was met with heavy shelling and gunfire from the presidential guard unit, three other security sources said, adding that a search was ongoing.

The sources all requested anonymity because they are not authorised to speak to the media.

They did not comment on the whereabouts of president-elect Mohamed Bazoum, who is due to be sworn in tomorrow after an election victory disputed by his opponent Mahamane Ousmane.

President Mahamadou Issoufou is stepping down after two five-year terms.

The president's office shared photos on Twitter of Mr Issoufou presiding over the swearing-in ceremony of two new members of the constitutional court yesterday morning.

Former US Sahel envoy J. Peter Pham earlier tweeted that both the president and president-elect were safe. The government of Niger was not immediately available to comment.

There have been growing attacks by Islamist militants as well as protests in the country following Bazoum's victory in a February presidential election runoff.

Ousmane, a former president who lost that contest, has rejected the results and said there was a fraud.

In pockets of the capital yesterday, Ousmane supporters took to the streets for a scheduled protest and clashed with police, who fired teargas to disperse them, according to witnesses, who also said roads out of the city had been closed.

Bazoum's election is the first democratic transition of power in the West African state that has witnessed four military coups since independence from France in 1960, including one which toppled Ousmane in 1996.

The heavy gunfire started around 3 am local time (5 am East African time) and lasted for around 30 minutes, according to a Reuters witness. By 10 am local time, traffic had resumed in the area and the situation appeared normal, said several witnesses.

The US Embassy in Niamey said it was closed for the day due to gunshots heard in the neighbourhood and warned that the security situation remained fluid in the post-election period.

Rising insecurity in the region caused by jihadists linked to al Qaeda and Islamic State has compounded economic challenges for Niger including drought, the Covid-19 pandemic, and low prices for its top export uranium.

A coup in neighbouring Mali in August last year overthrew president Boubacar Keita. Under pressure from regional states, the junta ceded power to a transitional government that will govern until elections next year.