The attacks on Thursday took place in Katsina State, one of the regions in northwest Nigeria hit by armed gangs known locally as bandits who carry out mass kidnappings for ransom and looting raids on villages.
Bandit militias stormed the villages of Unguwar Sarki, Gangara, Tafi and Kore in Sabuwa district late on Thursday, opening fire on residents, said Nasiru Babangida, Katsina state internal security commissioner.
"Twenty-five people were killed in the attacks on the four communities, 19 of them in Unguwar Sarki village alone," Babangida told local radio.
Several residents were injured while others were kidnapped by the criminals, he said.
"Most of those killed were vigilantes who came out to confront the bandits."
Many communities in northwest Nigeria have formed self-defense vigilante forces to fight off bandits in remote areas with little state presence, and the two sides are locked in a spiral of tit-for-tat killings and reprisals.
The bandits raided the villages in response to ongoing military offensives against their camps in the area and in neighboring Kaduna state where they have suffered a large number of casualties, Babangida said.
"The attacks were in retaliation for the aerial bombings of their camps in Katsina and Kaduna states that have killed more than 200 of them," he said.
The gangs who maintain camps in vast forests straddling Zamfara, Katsina, Kaduna and Niger states have made headlines for mass kidnappings of students from schools in recent years.
Bandits have no ideological leaning and are motivated by financial gains but there has been concern from analysts and officials over their increasing alliance with jihadists waging a 15-year armed rebellion in the northeast of Nigeria.