"But at midnight Paul and Silas were praying and singing hymns to God, and the prisoners were listening to them. Suddenly there was a great earthquake, so that the foundations of the prison were shaken; and immediately all the doors were opened and everyone's chains were loosed. And the keeper of the prison, awaking from sleep and seeing the prison doors open, supposing the prisoners had fled, drew his sword and was about to kill himself. But Paul called with a loud voice, saying, 'Do yourself no harm, for we are all here.' Then he called for a light, ran in, and fell down trembling before Paul and Silas. And he brought them out and said, 'Sirs, what must I do to be saved?'" (Acts 16:25-30).
Although Paul and Silas had been humiliated by being stripped and beaten with rods, their spirits were still filled with joy (cf. Phil. 4:4). Being locked up in prison in stocks with a bruised and bloody body was painful, but it could not quench true love for God and His will! These two godly men were not complaining but praying and singing to God in the middle of the night from a dark prison cell. They know the Lord can hear them, and the other prisoners are listening too (cf. Phil. 2:15,16). The Greek text literally indicates that they were singing their prayers to God. Likely it was difficult for them to sleep in the stocks and the throbbing pain in their bodies, so they turn their thoughts and words heavenward to their great God! Even in difficult, trying situations, there is always good to be done by those willing to seek it! Their attitude is much like that of the apostles in Jerusalem in Acts 5:40,41. They had been beaten for serving Jesus, and that caused them to rejoice. Abuse would not deter them from their God-given mission! The other prisoners listened eagerly. This was quite different than the sounds usually heard in a prison (e.g., cursing and profane jesting).
The fact that there was a great earthquake that did not collapse the roof, crumble the walls, or harm anyone yet opened all the prison doors and loosed everyone's chains is incredible! Such is clear proof that it was a divinely orchestrated event (cf. 4:31). An event with this much power and precision does not happen on accident (and those present would have deduced such). Not surprisingly, the keeper of the prison had dozed off in the darkness. There was no need for him to remain at full alertness at night when the prison was securely shut. However, it would seem that the quake disturbed his rest and he awoke to find the prison doors opened. His first impulse is to take his own life. He assumed the prisoners had escaped. He had failed at his duty, or so he thought, and he was as good as dead once his superiors found out. He reasoned it was better to die by his own sword than to be executed or perhaps tortured.
In the darkness Paul is able to perceive the course of action the jailer is about to pursue. He calls out loudly to stop him, informing him that no one had left. A light is brought and the jailer likely confirms the words of Paul. Why didn't the prisoners leave? Likely they were too shocked to do so, realizing the source of the quake. The jailer must have realized the origin of the earthquake also. His interaction with Paul and Silas, coupled with the divinely-provided earthquake, had changed him. In the beginning he certainly was not sympathetic to their cause. He had been given a duty (to "keep them securely"), and he took every precaution to do so. The behavior of Paul and Silas after the beating and in the prison that night had softened his heart to some degree (e.g., the singing, praying, and whatever dialogue they may have had with him). And now the open prison doors with all the prisoners still inside overwhelmed him emotionally. He knew enough to run to Paul and Silas with a light, and bow down before them in submission. He then brought them out of the dungeon (i.e., the inner prison) and asked - "Sirs, what must I do to be saved?" He knew they were men of God, and he begged them for knowledge of the way to life. The jailer had interpreted the earthquake as an act of God, and he knew he was in need of divine mercy. He needed help! Paul and Silas gladly teach him (and others) the gospel of Christ, as we will see in the coming verses.