LADING-LADING, Indonesia — He was in the front row praying with his brother-in-law when the mosque began to shake. Narto Aryadi clutched his arms around a large column and held tight.

The column tipped over but protected him from the second floor of the Jabal Nur mosque, which landed like a pancake on top of it. Mr. Narto had just enough room to turn over and start digging his way to safety with a chunk of debris, dragging his injured brother-in-law along behind him.

The distance was less than 20 yards. But it took Mr. Narto more than 12 hours of digging to clear a passageway under heavy beams that had fallen across their path. He also kept reciting every passage of the Quran he could remember.

“When dawn came, I thanked God and I realized I will be alive,” he said in an interview on Tuesday, a day after the ordeal. His brother-in-law was hospitalized.