AMERLI, Iraq — The children lined the unkempt boulevard in this northern Iraqi town on Tuesday to welcome some of the men who had saved them from the Islamic State in Iraq and Syria.

Convoy after convoy of armed men raced past, blaring victory music from loudspeakers and bristling with weaponry. They waved as the young residents clapped and chanted religious slogans, celebrating the men who had broken the militants’ chokehold on Amerli and allowed in the first shipments of food and water in nearly three months.

It took an odd coalition of Iraqi and Iranian militias backed by American air support to drive off the ISIS fighters. But for long weeks before, the minority Shiite Turkmens who live here held the line, waging a desperate campaign for survival as they took up arms to protect the estimated 15,000 residents.

Amid daily shelling and at least four major assaults by ISIS, the people subsisted on onion soup and dry bread. Children joined the front lines during the day because there were not enough men for two shifts. Without gas, families cooked on open fires fueled by sheep dung.