TALL AFAR, Iraq — The beat-up Hyundai station wagon turned onto the street, a signal that the party could begin. The women gathered at the door, ululating as children spilled past them to lob candy at the three boys who slowly disembarked from the vehicle.

For a moment, the boys — 11-year-old Ali Aoun and his two brothers, Khalil, 9, and Ahmad, 7 — stood by the car, looking dazed as relative after relative came to kiss their shaved heads.

Hours earlier, the three had boarded a bus along with 14 other children for the journey from eastern Syria to their families across the border in Iraq. It had been the last stop in a five-year ordeal.

It was 2014 when Islamic State mounted its genocidal rampage against the religious minorities who had long made Tall Afar and the bucolic plains of northwestern Iraq their home. The militants slaughtered thousands of Yazidis and Shiite Turkmens, groups they considered infidels. But they also kidnapped their children, seeking to indoctrinate them and press them into service as future sex slaves or child soldiers.

That these boys had escaped five years later was little short of a miracle. They had fled the eastern Syrian hamlet of Baghouz, 150 miles away, where the extremists are mounting their last stand against a U.S.-backed militia known as the Syrian Democratic Forces.

Yet they seemed drained of happiness as they sat in three plastic chairs arrayed in the family’s courtyard.

A woman brought out a table laden with bowls overflowing with candy. She placed it before the boys. The family gathered around them, some of them brandishing their smartphones to record the occasion.

But the boys didn’t move. They didn’t eat. They didn’t smile. They didn’t even look up from the floor.

Someone threw another handful of bonbons in a determined attempt to turn the mood festive. They smacked against the boys’ knees, but got no reaction.

A moment later, Ahmad’s face scrunched into a scowl before he began to cry. Khalil followed suit, while Ali buried his head in his hands, his body doubled over in the chair as if he were in pain.

Around them, the adults looked helpless, their eyes filling with tears. One of the men came forward and scooped Ahmad in his arms, trying to get any response. Finally, two women peeled them off their chairs and took them inside.

The boys’ homecoming should have been a moment of joy. But those who make it back from Islamic State’s clutches return to ravaged communities, and families ill-equipped to heal the scars of their time with the extremists.

And perhaps the most remarkable aspect of their bittersweet story is how many others share the same fate: Up until last week, the Aoun boys had been among more than 120 Shiite Turkmens and hundreds of Yazidi children still missing. It’s not clear how many remain or were killed.

The Aoun brothers’ bondage began for the most quotidian of reasons: A car broke down.

When the militants stormed Tall Afar in mid-2014, the boys’ family escaped along with hundreds of thousands of others to the town of Sinjar. But a week later, it was clear it too would soon fall into Islamic State hands.

The boys crammed into a car with their uncles and mother, while their father, Shehab Aoun, took other members of the family in another car. They took the road leading to the top of nearby Sinjar mountain, where they hoped to evade Islamic State.

“But the road was too crowded. One car stopped in the middle of the road and blocked the path, and they couldn’t get through,” said Aoun, 55, who worked as a farmer before 2014 but now is part of the Shiite-dominated militias known as the Popular Mobilization Forces.

The militants caught up with them. The men were taken away and killed; the women, including Aoun’s wife, were dragged off to become sex slaves (she remains missing); the three boys were sent to an Islamic State orphanage in Mosul.

There they found another Shiite Turkmen boy, Mahdi Ghazi Jolac, who was 6 at the time.

Mahdi had been brought to the orphanage along with his 5-year-old sister Laila and 4-year-old brother Jamil. His two younger siblings, Ali, who was 10 months old, and Ramleh, just 2 weeks old, were placed with Islamic State families to be raised as their own.

Mahdi, who had returned with the Aoun children on Monday, described his time with Islamic State as a series of moves, many of them mirroring the group’s retreat before the U.S.-led coalition’s offensives in Iraq and Syria.

The children were made to wear Kandahari-style clothes, the long tunic and pants set worn by many Islamic State members, he recalled, and put in an intensive program of religious study, punctuated by beatings for any perceived bad behavior.

“They taught us Islamic doctrine, creed, Quran, Quranic recitation,” he said.

By the time they had reached Baghouz in December, Islamic State was besieged on all sides. Matters turned desperate, and Mahdi said the children were fed nothing but lentils.

Then this month, he said, as a truce with the Syrian Democratic Forces ended, the head of the orphanage told the boys it was time for them to escape.

The children made the trek across the desert, dodging gunfire as well as Islamic State members who would force them to turn back, Mahdi said. (Mahdi’s family said two of his four siblings have been returned, but one remains with Islamic State and one has been adopted by a family in Turkey, which is fighting his return.)

The Aoun children and Mahdi made it to the Kurdish-led camps. There, a spokesman for the Syrian Democratic Forces filmed them and posted the video to Twitter. Five days later, they were in Tall Afar.

It’s too early to know whether the end of their captivity spelled the end of their suffering, said Mohammad Nathem, a 34-year-old businessman and activist from Tall Afar.

“The situation of these children is a crime. How will they be rehabilitated? There are no centers to help them, and the families themselves have been destroyed,” he said.

“Tall Afar can’t do anything for them. We don’t even have good schools here, and who will know how to handle their needs?”

For their part, the Aoun children seemed unwilling to believe they were home. Around them, their family members spoke the Turkic language of their ethnic group.

But the boys now could speak only Arabic.

As the family brought out trays of chicken and bulgur wheat, they ate silently.

“You were imprisoned? How did you escape from Daesh?” asked one of the boys’ uncles, speaking to Ali in a loud voice as if he were hard of hearing. (The uncle referred to Islamic State by its Arabic acronym.) To this, Ali said nothing, staring at the ground as he curled up in a corner of the room.

Finally his father pulled him to his side to have sugary tea, while one of his older brothers, 21-year-old Ibrahim, pulled the woolen hat from Ali’s head and rubbed his scalp. To his side, Ahmad kept eating, while Khalil, sitting in the lap of one of his relatives, stared at a cellphone.

A moment later, Ali brought his arm to his face, as if he were rubbing his eye.

He sobbed quietly as the family kept on talking.