listening to them
The pronoun "them" refers to Paul and Silas, who were praying and singing hymns to God.
so that the foundations of the prison were shaken
“which shook the foundations of the prison"
everyone's chains were unfastened
"everyone's chains came loose”