ABUJA (Reuters) - Islamic State West Africa (ISWA) insurgents overran the town of Rann in northeastern Nigeria on Monday evening, security sources said, a blow to President Buhari’s efforts to defeat the militants just weeks before national elections.

Buhari came to power in 2015 on promises to defeat the Boko Haram Islamist insurgency, from which ISWA split in 2016. ISWA has since become the dominant group in Nigeria’s northeast, with a surge in attacks renewing debates around security in the run-up to elections on Feb. 16.

Nigerian government forces fled during ISWA’s attack, along with residents of the town, the sources said, adding that the militants were setting buildings ablaze.

“The terrorists have invaded Rann, they’ve taken over, our guys are retreating,” said one military source, speaking on condition of anonymity.

Last month, ISWA launched a series of attacks that saw them take the town of Baga, the Nigerian headquarters of a multi-country force formed by Nigeria, Chad, Cameroon and Niger to fight the extremists, sending more than 30,000 people fleeing.

Last week, the military launched a counter-offensive and retook the town, saying in a statement it had given ISWA a “bloody nose”.

But the Nigerian military’s attacks have not deterred the insurgents, and security sources say the army has lost the initiative, with hundreds of soldiers killed, low morale and a lack of equipment.