A gang of cattle thieves has killed 41 vigilantes in Nigeria's troubled north in a forest ambush, police said.

The incident happened on Thursday in Katsina state when scores of vigilantes from several villages in the Bakori district mobilised to track down the gang, which had stolen cattle from a local the previous day.

Katsina state police spokesman Gambo Isah said late Friday the vigilantes were ambushed by the thieves, who killed 41 and injured two others.

He said the vigilantes were armed with Kalashnikov rifles.

"The hoodlums shot and killed 41 Yansakai (vigilantes) and wounded two," he said, adding that their bodies had been recovered.

"A joint security operation is currently ongoing with a view to bringing the perpetrators to book," he added.

Local residents said 52 people had been killed in the attack in Yargoje forest in the neighbouring Kankara district.

"The police went into the forest between Thursday and Friday and brought 52 bodies of the vigilantes in two batches," Idris Usman said.

He said dozens of other vigilantes were also brought to the hospital with injuries.

Another local, Abdullahi Sada, gave the same toll, saying the attackers were from neighbouring Zamfara state.

Katsina is among several states in northwest and central Nigeria terrorised by criminal gangs who raid villages, kill residents, kidnap for ransom, steal cattle and burn homes after looting them.

The gangs maintain camps in a vast forest straddling the states of Katsina, Zamfara, Kaduna and Niger.

The southern part of Katsina, including Bakori and Kankara, lies near the border with Zamfara and have been repeatedly targeted by gangs based in the adjoining state.

More than 300 schoolboys were kidnapped by bandits in Kankara in December 2021. The pupils were taken to Zamfara and released after ransom was paid.

Local communities then formed vigilante groups to fight attacks by criminal gangs.

But the militia were outlawed by state authorities for lack of basic security training which, they say, exposes them to unnecessary danger.

"This unfortunate loss of lives of these vigilantes was the result of taking laws into their (own) hands," Ibrahim Ahmad Katsina, security adviser to the governor told AFP.

"We have told communities not to go after terrorists when they attack them but to promptly inform security agencies," he added.