For 82 days and nights, Muammar Kamal stood watch from the roof of his home with a foam mattress, a pair of binoculars and his Kalashnikov rifle. Several hundred yards away across a sun-baked field, the young lawyer could see a black flag fluttering from a dirt barrier where Islamic State forces were dug in.
By Monday afternoon the flag was gone, as were the militants, and as he climbed to the roof, Kamal left his gun behind.
"You can go back to carrying just a pen and paper to work," his cousin said, laughing.
The people of Amerli were in a buoyant mood after holding off the Sunni Arab extremists who had surrounded the town 100 miles north of Baghdad. The militants had threatened to slaughter its 15,000 ethnic Turkmen residents, whom they regard as infidels because they are Shiite Muslims.
Amerli's teachers, farmers, police officers and white-collar professionals took up arms to defend their homes for nearly three months, but the Islamic State fighters weren't flushed out until Monday, after a major, two-day operation by an unusual partnership of Iraqi and Kurdish soldiers, Iranian-backed Shiite militias and U.S. warplanes.
In the Islamic State militants' months-long march across northern and western Iraq, this was believed to be the first time that a town had managed to hold off an invasion. Kamal's neighborhood at the edge of Amerli bore the scars of battle: his rooftop pierced by bullet holes, a water tank speckled with small-arms fire, a neighbor's staircase collapsed by a mortar round.
The siege finally lifted, Amerli residents spilled into the dusty streets, mugged with gun-waving Shiite fighters and clapped one another on the back, reveling in a victory that many here had thought improbable.
"We didn't think the siege would end with us alive," said Uday Fikran, a bearded fisherman whose handgun was still holstered to his bony hip. "We were ready to die for our families."
Many did lose their lives, felled by attacks or illnesses that raced through the town after the militants cut off water and electricity and food supplies ran low. Residents said dozens had died, including pregnant women who did not survive labor and babies who were deprived of formula.
By the end, Fikran's family was subsisting on bread, untreated water and cans of tomato paste. He had no access to the lake where he usually fished; even now, he is unsure whether he can go there because it is near several Sunni villages. He clutched at the jeans that had bunched up around his waist; he figured he had lost 20 pounds.
For the local police and volunteers defending the town around the clock, cigarettes ran out early, leading some to start smoking grape leaves. But their heroics won them universal admiration.
Mohammed Ahmed's brother, a police lieutenant, was supervising a checkpoint early in the morning on Aug. 2 when an Islamic State tank attacked. Several police officers retreated, Ahmed said, but his brother, Wisam, fired back with only his aging Kalashnikov. Wisam was killed and all the others suffered injuries.
"We're very proud of him," Ahmed said. "He died defending our town."
As black smoke billowed from the surrounding villages where militants had holed up — a sign of the fighting that lasted until Monday morning — trucks laden with food, gasoline and relief supplies began to arrive. Residents unloaded sacks of flour and boxes of rations donated by Shiite political parties and Islamic relief groups as uniformed militiamen stood guard.
The town has become a symbol of resistance among Shiites who, even though they are a majority in Iraq, see the rise of the Al Qaeda breakaway group as an existential threat. Graffiti scrawled along the main road read "Iraq's Stalingrad," a reference to the battle between Russia and Germany that, many believe, turned the tide of World War II.
Militia commanders said the operation was led by the Iraqi national army, which pushed through villages to the east of Amerli that had been controlled for weeks by Kurdish Iraqi forces. The Pentagon said U.S. warplanes launched four airstrikes in the area, including one Sunday that destroyed an Islamic State tank.
But even in the afterglow of victory, the Shiite militiamen were not eager to share credit with the United States or the Kurds, who have often opposed the Shiite-led government in Baghdad.
Checkpoints leading to Amerli on Monday were manned by an array of armed groups supporting Iraq's government, including some that battled U.S. forces before they withdrew from Iraq in 2011.
At one checkpoint controlled by the Iranian-sponsored Kataib Hezbollah group, identifiable by its green-and-yellow flag, a young fighter said he was watching to make sure the Kurdish flag wasn't flying anywhere in Amerli without the Iraqi flag alongside it.
"I don't want anyone to twist the facts that the Kurds liberated Amerli, when we've been here for the last three months," he said.
At the headquarters of the Badr Organization in the town of Tuz Khurmatu, about 15 miles north of Amerli, a militia fighter who gave his name as Abbas blamed Kurdish forces for failing to secure Sunni villages that Islamic State eventually took over. He praised the Iraqi air force, which periodically delivered food and weapons to Amerli and also launched airstrikes, but shrugged when asked about the U.S. role, which included dropping relief supplies Saturday.
"I didn't see their planes," he said.
Amerli residents said they had long been at risk because theirs was the only majority Shiite town in a Sunni-dominated area. The nearby hamlet of Suleiman Beg was home to former members of Saddam Hussein's Sunni-led Baath Party, who formed an alliance with Islamic State and seeded the surrounding villages with Sunni fighters.
"We used to be very careful driving past that place, always looking in the rearview mirror to make sure no one was following us," said Kamal Mohammed Ali, 64, a retired teacher.
With Sunni snipers firing from rooftops, Iraqi forces pummeled Suleiman Beg overnight Monday and finally declared it clear by noon. The town was abandoned by evening, the gates to homes left wide open and Shiite banners freshly hung on crumbling walls.
A proposal to bulldoze the neighboring villages was gathering steam in Amerli. The town's only Sunni mosque, which had served 150 families that fled before the siege, now has "Husseiniya" scrawled on its walls, marking it as a Shiite place of worship.