Rescuers are racing to pull dozens of students and workers from under the rubble of a school building that collapsed in East Java, Indonesia. Three people have been killed and 99 others hospitalised, some of them with critical injuries, officials said Tuesday, adding that the death toll may rise.

At least 38 others, many of them teenage boys remain trapped under the Al Khoziny Islamic Boarding School in the East Java town of Sidoarjo. They had gathered for prayers when the building gave way on Monday.

The two-storey building had an unstable foundation and could not support the weight of the construction of two more floors, the disaster mitigation agency said. The girls were praying in another part of the building and managed to escape, according to the Associated Press. Students in the school are between the ages of 12 and 17.

Footage on local media show the collapsed part of the building completely sunken in, with large slabs of concrete sticking out. Crying and shouting can be heard from the rubble, authorities said, while anxious relatives have camped out at the school overnight awaiting news of their loved ones.

Dozens of rescuers have been searching overnight for survivors, but the rescue was temporarily suspended on Tuesday, with authorities saying the building is at risk of further collapse. The collapsed building has taken on a pancake type structure with layers of concrete slabs leaving only narrow voids, unstable conditions, and the possibility of survivors still trapped, said Mohammad Syafeii, head of the search and rescue agency Basarnas.

His agency is preparing for a specialised operation and has deployed units from around the region that will be equipped with special extrication tools, he said. Mr Syafeii also laid out the dilemma with the use of heavy equipment, such as cranes and excavators. While they help lift the concrete slabs and open access, shifting the slabs may also endanger the lives of survivors still trapped beneath the rubble.

Students who survived the incident have been recounting their harrowing escapes to local media. Seventh grader Muhammad Rijalul Qoib said hundreds had gathered to pray when they heard the sound of falling rocks. It got louder and louder, the 13-year-old said, adding that he immediately ran outside. Another student, Sofa, saw his classmates with lots of injuries including broken bones.

Sidoarjo town's regent claims the school's management had not obtained permits for the expansion of the building, which had been under construction. Indonesia's construction sector has a poor safety record, rated among the worst globally by the International Labour Organization.