Seven boys have been arrested in connection to a fire at a religious boarding school in Malaysia that killed 23 people, including 21 pupils, authorities said.

Kuala Lumpur police chief Amar Singh said on Saturday that the boys, aged 11 to 18, were rounded up after they were identified in CCTV footage from a neighbouring building that showed them near the school the night of the fire.

The pre-dawn blaze on Thursday at the three-story Darul Quran Ittifaqiyah "tahfiz" school blocked the lone exit to the dormitory on the top floor, trapping students behind barred windows. Two adults and 21 students, aged between six and 17, were killed.

"From our investigation, the motive behind the mischief was due to a misunderstanding after the suspects and some tahfiz students mocked each other a few days before the fire," Singh said during a televised news conference.

Singh said six of the seven suspects tested positive for drugs. Two of them had been detained before, one on charges of vehicle theft, another for rioting, he added.

He said it is believed that two cooking gas tanks were brought up to the top floor and used to start the fire, which spread rapidly and took firefighters an hour to extinguish.

READ MORE: Fire kills at least 20 at religious school in Malaysia

Singh said the seven are all school dropouts and will be under police remand for a week. He said the case has been classified as murder and mischief by fire.

Singh added that the school is also being investigated for flouting building safety rules.

Officials have said the school was operating without a fire safety permit and licence, and that a dividing wall was illegally built on the top floor that blocked the victims from a second exit.

Scenes of horror

Firefighters and witnesses have described scenes of horror - first, of boys screaming for help behind barred windows as neighbours watched helplessly, and later, of burned bodies huddled in corners of the room.

Officials initially said they suspected the fire was caused by an electrical short-circuit but later said this was not the case.

The charred bodies were released on Friday to family members after being identified through DNA testing and buried the same day.

Hundreds of relatives and well-wishers mourned as bodies of 11 boys, wrapped in white shrouds, were lowered into the graves in a cemetery outside Kuala Lumpur.

In another cemetery near Kuala Lumpur, two siblings and their cousin were laid to rest in the same grave while others were taken to their hometowns. The burials were sponsored and arranged by state Islamic authorities.

The fire has renewed calls for better regulation of religious schools, mostly privately run and not supervised by the education ministry because they come under the purview of state religious authorities.

Local media reported there are more than 500 registered tahfiz schools in Malaysia but many more are believed to be unregistered.

Data from the fire department showed that 1,083 fires struck religious schools in the past two years, of which 211 were burned to the ground.

The worst disaster occurred in 1989 when 27 female students at a religious school in Kedah state died when fire gutted the school and eight wooden hostels.