KOBANI, Syria — As a 14-year-old whom we’ll call Lawand sat in the jail cell he shared with 21 other teens, he could hear his friends screaming from what inmates called the “torture room” downstairs. The only thing on his mind was fear. His friends had been put in car tires, hung from the ceiling and beaten. He knew he’d soon be taken downstairs himself. Taking the kids from the 10-foot-by-15-foot cell one by one, it took the jailers three days to interrogate them all.

Lawand is one of some 150 students from the northern Syrian city of Kobani who were kidnapped in late May by militants from the Islamic State of Iraq and al Sham, or ISIS as it was known, the al Qaeda offshoot that has declared a caliphate to promote its extremist brand of Islam. The teens had been on their way home from end-of-year exams in the Syrian city of Aleppo when they were abducted. Lawand was one of just nine lucky enough to escape after two months of captivity. The rest are still in the hands of the so-called “caliph.”

Kobani is in a Kurdish region of Syria, and although it is defended by an ethnic militia called the People’s Protection Units, or YPG, it is surrounded by ISIS on three sides. The fourth side is the border the region shares with a wary Turkish government. As the YPG battles ISIS, the extremists kidnap Kurds who venture from their turf. The small city’s population has meanwhile swelled with desperate internal refugees.

PHOTOS: Inside Kobani, Syria

Lawand and the other students had to travel through territory vulnerable to ISIS when they left Kobani to take their exams in Aleppo. The militants warned them not to attempt a return. But the students chanced it, piling into three buses for the dangerous journey back home.

They stopped for a rest at a small restaurant by the Euphrates River, and then they saw ISIS militants approach in two pickup trucks. The militants were nice to the kids at first, but Lawand was terrified—he’d never been in close contact with armed men in suicide-bomber vests. The kids were told they’d be released in three days, but that didn’t relieve their fear.

The militants first escorted the buses to a Sharia court, where their hard-line version of Islamic law reigns supreme. The kids learned little there of their fate, instead getting the feeling that their captors were simply putting them on display. Then they were escorted to a mosque, where they spent the night.

The next day they met a local ISIS official, or emir: a Saudi man who introduced himself as Abu Musa. Speaking gently, he reassured the kids they would soon be released.

Abu Musa and two of his men were responsible from the kids, and the first week was easy. They were fed with good food and juice and given classes on Islam each day. The classes on jihad were to start later. They had the rest of the day to play football in the yard. They were told, again as gently as such a message could be, that they were unbelievers but would soon repent.

But then Abu Musa and his two men—one of whom, like Lawand, was only 14—said they had been called to Iraq on a suicide mission: “We are sorry if we did any harm to you. We are on our way to heaven now.”

Things grew darker from there. As the first week bled into a second, new captors showed Lawand a list of YPG soldiers and officials who were members of his family, and asked him to confirm it. He pretended not to know the familiar faces on the list. That’s when the gentle attitude of his captors changed. Lawand was taken to a former regime prison with other kids who refused to cooperate.

Their small cell had just a tiny window to let some sunlight in. The group of five gradually swelled to 22. Also imprisoned with the boys: a Libyan member of ISIS who apparently had gotten into a dispute with the emir. The Libyan continued the boys’ religious lessons inside the cell.

They would be taken to the torture room downstairs, one by one. When it was Lawand’s turn, he was first put in a car tire and beaten. Then he was hung from the ceiling by his hands, and beaten again. He could take this punishment for only half an hour before admitting that the list of his YPG relatives was accurate. He was taken back to the cell upstairs, where his time in detention would span 20 days. The kids were allowed to spend an hour each day in the yard; older prisoners got only five minutes.

Lawand saw familiar faces, among them an uncle who was a teacher kidnapped while he was on his way to Aleppo to collect his salary. There were also captured fighters from the YPG and some of the rebel groups engaged in an internal war with ISIS. There was even a Westerner, who appeared to be unhinged—Lawand observed the man muttering to himself in a language he couldn’t understand.

When the Muslim holy month of Ramadan began, in late June, Lawand was allowed to leave the prison. He rejoined the other students at a nearby school. The kids were forced to observe the holiday’s daily fast in the July heat. When one was caught taking a sip of water, the militants tied him to the goalposts of a soccer field, making his body into a cross. Then they scalded him with hot water and beat him with sticks.

Some kids tried to escape. One was successful. When the rest were caught, they were put through mock executions, and more torture. Some had knives pressed against their throats for what seemed like an hour.

The daily Islam lessons continued. Only now they included subjects like “What is Jihad,” “Kinds of Jihad” and “How to Jihad.” The boys were forced to memorize the Qur’an. Their captors showed them videos ISIS had produced of beheadings and suicide bombings, and of the Sunni militants blowing up Shiite shrines. The screenings ended only when the projector broke.

One morning, two Tunisians and a Jordanian told Lawand they were leaving for a battle in Kobani, his hometown. The Jordanian later returned with a wound received in battle, he said, shot by a female fighter from the YPG. The Islamist militants seemed to be terrified of these notorious female fighters.

Finally, in late July, Lawand and four friends began to plan their escape. At night, the only thing between them and the courtyard was their room’s locked door. The guard outside was usually fast asleep. They picked the lock, crept out the door, jumped the courtyard’s wall, and made a run for it through the darkness. Then they hid in a nearby construction site. At daybreak, they borrowed a small sum of money from a passing family, then called their families from an Internet cafe. The family sent a trusted Arab driver who could navigate the ISIS checkpoints. On July 24, the boys returned home.