According to the police, the clashes occurred Monday in the Zuru district of Kebbi state.
The gunmen were heavily armed and were fleeing military operations in neighbouring Niger state when they were intercepted by the local vigilantes.
President Muhammadu Buhari condemned the killings while urging security forces to increase efforts.
In January, Nigeria’s government labelled the criminal gangs as terrorist groups in an attempt to bring tougher sanctions against the gunmen and their informants.
Last year, criminal gangs raided a number of schools and kidnapped students in a bid to squeeze more ransom out of local communities.