In April, he said, the prisoners were moved to a rural villa, also run by Mohammad, where a boy who appeared to be 12 was allowed to beat some of the prisoners and shock them with Tasers.

In May, he said, they were moved again, this time to a base run by Ahrar al-Sham, where an elder took an interest in their plight. He ordered them to give written statements about their torture by the Nusra Front, and said their cases would be re-examined and that they might be released.

Instead they were transferred to cells in two other bases, also run by Mohammad and the Nusra jailers. In mid-July, the jailers removed the Moroccan and later a dentist they had detained, leaving the Americans alone.

This allowed a fresh opportunity to try to escape. Their cell was in a basement; the mesh and welding on one window was damaged and had been only partially repaired.

Mr. Schrier said he stood on his cellmate’s back and unraveled wires, opening a hole large enough to fit his head and one arm. But he got stuck and had to return inside and rewire the mesh.

He and his cellmate argued over whether to try again. After a few days, he said, his cellmate agreed. Mr. Schrier opened a larger hole.

After the morning prayer, just before dawn, Mr. Schrier said, he pushed both arms out and followed with his head.