SURT, Libya — Perched on a doorstep, the teenage Juma brothers whiled away the afternoon with a lazy game of checkers, pushing pebbles around a board chalked in the dust, seemingly oblivious to the crackle of gunfire and boom of artillery a few miles away.

They had fled their home in Surt, the Islamic State’s Libyan stronghold, three weeks earlier as a Libyan fighting force, quietly supported by American and British Special Operations troops, swept toward the coastal city from the desert. Now, as the siege intensified, the Juma brothers were sitting out the battle at this farmhouse on the southern edge of Surt, their apprehension tempered by a wave of sheer relief.

“Life was hell,” said Hammad, a lanky 16-year-old with a shock of unkempt hair, describing the Islamic State’s brutal 18-month rule. Cafes were closed, schools renamed and girls flogged for not covering their faces, he said. He watched in horror as a hooded figure chopped off the hand of a thief — a desperate man who had stolen medicine. Nightmares came after the Islamists crucified people accused of crimes at a major traffic junction, then left their bodies to rot.

“I would wake in a panic, thinking I was suffocating,” he said. His brother Mohammed, 19, nodded in agreement. The Islamists had executed his friend Abdullah by pushing him from a tall building, accusing him of blasphemy. Abdullah was 15 years old, Mohammed said.