The incident took place in a village which is a few dozen kilometres from where militants killed four US soldiers in an ambush on October 4.
Gunmen on pick-up trucks and motorcycles coming from Mali killed 13 gendarmes and wounded five more in an attack on their base in western Niger, security sources said on Saturday.
The village is a few dozen kilometres from where militants killed four US soldiers in an ambush on October 4 that has thrown a spotlight on a US counter-terrorism mission in Niger, a country that straddles an expanse of the Sahara.
Niger's military officials confirmed the attack. The assailants crossed over the border from Mali and drove up to the village of Ayorou, about 40 kilometres (25 miles) inside, before springing their attack, the security sources said.
"They were heavily armed. They had rocket launchers and machine guns. They came in four vehicles each with about seven fighters," said a security source on the scene.
Reinforcements later arrived and stopped them as they tried to cross back over the border, another security source on the scene said, triggering a gun battle. They escaped into Mali and were being pursued, he added.
"Land and air forces are pursuing the assailants with a view to neutralising them," a statement from Niger's military said, confirming the death toll.
In the initial attack one of the assailants was killed in an exchange of fire but others managed to make off with four Nigerien army vehicles, the first security source said.
Since taking over swathes of northern Mali in 2012, and then being scattered by a French-led counter-offensive the following year, militants have established themselves in lawless spaces across the desert.
They have used these areas as a springboard for a wave of attacks that threaten to destabilise West Africa.
Fighters have inflicted damage on military outposts, killed security officials and civilians, kidnapped Westerners and sometimes mounted high-profile attacks on hotels and resorts across the region, including in Burkina Faso and Ivory Coast.
Several militant groups and well-armed ethnic militia operate in the area along the Mali-Niger border. There have been at least 46 attacks there since early last year.
However, officials suspect many of them, including the ambush on the joint US-Niger patrol, to be the work of Daesh in the Greater Sahara, led by Arabic-speaking north African militant Adnan Walid al-Sahrawi.
He has pledged allegiance to Daesh militants in Iraq and Syria, although the extent of their ties are not known.
No group has yet claimed responsibility for Saturday's attack, nor the one that killed the US soldiers.
Responding to its ever growing militant threat, Mali on Saturday announced a year extension of a state of emergency.
"I hope we won't need to continue extending the state of emergency," Defence Minister Tiena Coulibaly told reporters. "We hope that before October 31, 2018, order will be restored."
The increasingly fluid, cross-border nature of the militant threat forced the Sahel countries Mali, Niger, Chad, Mauritania and Burkina Faso to launch a joint force - known as "G5 Sahel" - in July, to try better coordinate policing their deserts.
But it has yet to receive a commitment to more than a fraction of the donor funding that it needs. A UN Security Council delegation was in Mali on Saturday to discuss the force.
"This tragedy is one more element that ... underlines the urgency of a strong and determined response through the creation of the joint G5 Sahel force," French permanent representative to the UN Francois Delattre told journalists during the meetings.