HONG KONG — Twenty-four people, most of them children, were killed in a fire on Thursday at an Islamic boarding school in Kuala Lumpur, Malaysia’s capital, when they became trapped by a locked door and barred windows, officials said.

Fire officials said many of the bodies found in the school’s dormitory had been burned beyond recognition, but they confirmed that the remains belonged to 22 boys, ages 13 to 17, and two teachers.

“Based on our initial investigations, the position the victims were found indicated that they tried to escape through the windows but were stopped due to the fixed grills on the windows,” Datuk Soiman Jahid, a deputy director general with the fire department, told reporters at the scene.

The fire broke out Thursday morning on the top floor of the three-story school, Tahfiz Darul Ittifaqiyah, where students are taught to memorize the Quran. The local news media broadcast images of charred bunk beds, and on social media, users shared photographs of covered bodies being unloaded at a morgue.