Ammon and his brethren who were cast into prison (v. 20) were not the sons of King Mosiah who went on a mission to the Lamanites. They were Ammon and sixteen men who went to the land of Lehi-Nephi and found the people who had left Zarahemla years before. It was King Limhi, the Nephite king, who put Ammon and his brethren in prison (see Mosiah 7:1–9; Omni 1:27–30). Thus some ninety years had passed since the first imprisonment, from about 121 B.C. to about 30 B.C.
The encirclement “as if by fire” (Helaman 5:23) was undoubtedly the glory of God that may not always be discernable to the physical eye. The Prophet Joseph Smith taught: “Spirits can only be revealed in flaming fire and glory. Angels have advanced further, their light and glory being tabernacled; and hence they appear in bodily shape” (TPJS, 325). Apparently angels were attending to Nephi and Lehi. Nephi and Lehi recognized the presence of God in their midst (v. 26).
The shaking of the prison (v. 27) was similar to Alma and Amulek being loosed from prison in the city of Ammonihah (see Alma 14:17–29). There is also a similar incident in the Bible. Paul and Silas were loosed from prison in Philippi by an earthquake and the power of God (Acts 16:23–40).