Gunmen on motorcycles raided the town of Rann in Kalabalge district overnight Friday to Saturday and opened fire on homes, fleeing residents said.
“They opened fire on homes as we slept and killed seven people before carting away our food supplies and drugs from the only clinic in the town,” Rann resident Abba Abiso said.
The Nigerian army confirmed the attack in a statement on Saturday, saying it lost two soldiers while 16 Boko Haram Islamists were killed.
“The troops killed seven of the attackers instantly while quite a number escaped with gunshot wounds,” the army said.
“During clearance operations this morning, the troops discovered nine more Boko Haram terrorists dead bodies in the surrounding areas. Therefore the total number of terrorists killed was 16,” it added.
Residents had fled into Cameroon and the town of Gamboru, 28 kilometres (17 miles) away.
Another witness Ari Ngamsu added: “The Boko Haram gunmen planted two high calibre explosives on the way outside the town but soldiers from Gamboru succeeded in defusing them at daybreak.”
Both witnesses spoke on Cameroonian phone lines, the only means of communication available following the destruction of telecom masts by Boko Haram in previous attacks.
The Nigerian army also said it recovered a machine gun, a rocket propelled grenade and ammunitions from the insurgents, two of whom were captured alive.
Rann and nearby villages have been been targeted in a number of attacks by Boko Haram despite successes by the Nigerian military that have pushed the Islamists out of some areas.
The attacks have forced villagers to flee their homes, returning to them after they were clawed back by the military.
Last month the insurgents sacked neighbouring Wumbi and Jikana villages outside Rann, killing eight people and looting food supplies.
Boko Haram which seeks to impose strict Islamic law in northern Nigeria, has been blamed for some 20,000 deaths and displacing more than 2.6 million people since 2009.