Nearly 500 men and boys have been rescued from a building in the northern city of Kaduna, where the detainees were allegedly sexually abused and tortured, Nigerian police said.
Children as young as five were among those in chains at what was thought to be an Islamic school, officers said.
Kaduna police chief Ali Janga told the BBC the building was raided after a tip-off about suspicious activity.
He described it as a “house of torture” and a place of human slavery.
Eight suspects, most of them teachers, were arrested. The police chief said the detainees – some with injuries and starved of food – were overjoyed to be freed.
The detainees said they had been tortured, sexually abused, starved and prevented from leaving – in some cases for several years.
“I have spent three months here with chains on my legs,” Bell Hamza reportedly told Nigerian media.
“This is supposed to be an Islamic centre, but trying to run away from here attracts severe punishment; they tie people and hang them to the ceiling for that.”