LAGOS, Nigeria — Hundreds of boys and men have been rescued from a building in northern Nigeria where they had been beaten, starved, sexually assaulted and chained, police said Friday.

Visible marks on their bodies showed that some had been tortured, police spokesman Yakubu Sabo in Kaduna State told The Associated Press, as shocked authorities tried to track down the families of what appeared to be some 400 victims.

"The condition under which we found the victims was so dehumanizing, many of them were chained," Sabo said.

Police carried out the rescue on Thursday following a tip. It was not immediately clear what led to police being contacted, or how such a vast scope of alleged abuses managed to go unnoticed.

Local television footage showed most of the victims in very bad condition, with some walking with difficulty.

The building's owner told police the children had been brought by their families to learn the Quran or because they had problems such as drug addiction. But police said the place was not licensed to run any reformatory or educational program.

Some of the male students of "different nationalities" sit on the floor in chains outside a torture chamber on Sept. 26, 2019 in the Rigasa area of Kaduna in northern Nigeria after being rescued by police. AFP - Getty Images

The owner and six others who were said to be teachers have been arrested, the police spokesman said.

Boys can be seen begging on the streets in cities across largely Muslim northern Nigeria. They often are sent away by their families for Quranic training but then can be turned out into the streets by their new guardians to beg to earn their keep.

The newly discovered abuses, authorities said Friday, were another level entirely.

An aide to President Muhammadu Buhari, who comes from the north, earlier this year noted the widespread view that the "almajiri" learning system associated with begging was a "security challenge and a scar on the face of Northern Nigeria."

But the aide, Garba Shehu, rejected reports that the president had banned the system, saying a ban would need to follow due process and consultation with relevant authorities.

"Indeed, the federal government wants a situation where every child of primary school age is in school rather than begging on the streets during school hours," he said. "At the same time, we don't want to create panic or a backlash."