BEIRUT, Lebanon — The boy did not want to see a beheading, so he held his mother’s hand tight and tried to close his eyes. But seeing it was mandatory when the Islamic State ruled his hometown in northern Syria: If you were out on the street, you had to watch.

The boy, now 11 and a refugee in Beirut, reckons he saw 10 beheadings, and once he saw a man accused of a crime being thrown off the top of a building. Videos of executions were shown after the executions — and children were invited to watch inside mosques. “Some of my friends, they used to go and watch,” said the boy, who gave only his first name, Muhammad. “They liked it.”

Even by the brutal standards of the Syrian civil war, children growing up in areas ruled by the Islamic State have experienced and witnessed astonishing brutality. Schools have been closed for years. Polio has made a comeback. Boys have been recruited to fight.

Now, as foreign militaries and local militias try to flush out the Islamic State from its last redoubts in Syria, children fleeing the violence have to dodge airstrikes, snipers and then thirst and scorpions as they make their way across the desert.