The attackers stormed the mosque in Maigamji village, in Katsina state, during evening prayers Saturday and carried out the kidnappings after shooting and wounding the imam and another worshipper, said local police spokesman Gambo Isah.
“Our men mobilized and went after the bandits and succeeded in rescuing six of the worshippers from their abductors, while efforts are underway to free the remaining 13,” he added.
The two people wounded were being treated in hospital, he added.
Northwest and central Nigeria have been terrorised by criminal gangs locally known as bandits, who raid villages stealing cattle, kidnap for ransom and burn homes after looting supplies.
Hostages are usually released after a ransom is paid to the gangs, which take refuge in the vast Rugu Forest. It straddles four states in northwest Nigeria, including Katsina.
Last month, 15 people were killed and several others wounded in a series of bandit attacks on villages in neighboring Kaduna state, the authorities said.
Nigerian President Muhammadu Buhari has been under intense pressure to end the violence before he leaves office next year at the end of his eight-year tenure in office.
There is growing concern over an alliance in the northeast between the bandits and jihadists waging a 12-year insurgency to establish a caliphate.