HAWIJA, Iraq -- The jubilant outpouring that erupted in the heart of Hawija on Friday, the day after Iraqi forces claimed victory there, celebrated more than the fact that the Islamic State militants had finally been routed from the city, their last major urban stronghold in Iraq.
For many of the Shiite Muslim militiamen, who sped through the streets in pickups, flying militia colors and blaring religious music on loudspeakers, and the federal paramilitary police, who feasted on mutton and rice, their swift two-week victory represented the beginning of the end for militants who just three years ago ruled a third of Iraq.
"Game over," said Gen. Sabah al-Aboda of the Iraqi police, as he chewed a date in the shade of a collapsed storefront. "When they lost Mosul, they were broken."
General Aboda and other officers said the militants had been badly led and poorly supplied since they were driven from Mosul, Iraq's second-largest city, after a punishing nine-month battle that ended in July. They lost some of their best commanders and cadres, the commanders said, and their supply lines to Syria were cut by Iraqi forces.
Beyond that, officers and soldiers said, hundreds of militants never fired a shot in the Hawija operation. Following their commanders' orders, they fled north with their families to surrender to Kurdish forces, they said.
But others stayed and fought, the troops said. Most were killed, though some escaped and a few were taken prisoner, according to General Aboda.
On Friday, corpses of several militants lay where they had fallen, some with weapons still at their sides. Downtown Hawija, the site of the heaviest fighting, was a jumble of collapsed walls and crushed storefronts.
Kareem Gita, a Shiite militiaman who commanded a checkpoint in the shattered city center Friday, said many militants had lost the will to fight.
"Their leaders failed them," he said. "A lot of fighters ran away. The rest, we killed."
A handful of militants remained holed up in the city on Friday, General Aboda said. He said Iraqi forces were searching for them as engineering teams worked to clear streets and buildings of roadside bombs and booby traps.
Fighting continued just outside the city. Gunfire rattled in the distance and pillars of black smoke spun skyward as Iraqi troops pursued fleeing militants north of Hawija. Col. Ryan Dillon, the spokesman for the American-led coalition forces in Baghdad, said the militants were operating from a shrinking slice of territory.
Assuming Hawija's outlying districts are finally cleared, the Islamic State in Iraq would be left with a string of desert outposts in the Euphrates River valley and the city of Qaim on the Syrian border. The group still controls significant territory in Syria.
But the militants never made much of a stand in Hawija. For the first week or so, commanders said, some fought back as government troops squeezed them from three directions in outlying areas. Trapped, they made a final stand in the city center. After three days of urban fighting, commanders said, the battle ended on Thursday.
Burned-out civilian vehicles, some upturned and others riddled with bullet holes, lay among rubble in the city center. Soldiers said many had carried Islamic State fighters.
But virtually no destroyed military vehicles were visible, suggesting that militants in and around Hawija can no longer obtain the gun-mounted Humvees and armored troop carriers they used in Mosul.
"They don't know how to fight anymore," said Rohaid Talal, 22, a Shiite militiaman.
Before the operation, Iraqi forces dropped leaflets instructing residents to flee. About 75,000 to 80,000 took refuge in outlying districts, according to Naji Ibrahim Hawas, head of the Hawija provincial council. Those residential areas seemed mostly untouched.
For civilians, who began to emerge at the city's edge on Friday, the defeat of the Islamic State offered salvation after three years under the militants' harsh rule. Like residents of other Sunni cities controlled by ISIS, they described public beheadings in the city square, people shot in the foot if caught with a cellphone, and beatings for such offenses as wearing dishdasha hems too low or beards too short.
"They beat me with a belt in front of my children -- it shamed me," said Raad Mohammed Jasim, 38, who said he was jailed for three weeks by militants who stole his sheep and car.
Abdul Basit, 21, who like Mr. Jasim remained in the Hawija district under ISIS rule, said he was shocked that so many militants had fled without a fight because they had seemed so terrifying and ruthless.
"Just seeing their faces and their beards made me tremble," Mr. Basit said.
The sight of Shiite militiamen parading through a Sunni city did not seem to alarm many residents.
"They helped liberate us," said Mr. Hawas, the provincial council leader. "We prefer anyone to Daesh," he added, using an Arabic acronym for the Islamic State, also known as ISIS or ISIL.
He was preparing to slaughter 30 sheep to thank government forces, including the militiamen. He said Shiite militia units will soon hand control of Hawija to local police and to Sunni tribal leaders.
From 2005 to 2007, Sunnis and Shiites fought a brutal civil war. In 2013, Hawija was at the forefront of a brief uprising that pitted Sunni gunmen against the Shiite-dominated government of Nuri Kamal al-Maliki, then the prime minister.
Human rights groups have accused Shiite militiamen in liberated Sunni cities such as Falluja of executing Islamic State prisoners and civilians accused of supporting them. Several militants who surrendered to Kurdish forces last week said they feared execution if captured by Shiite militiamen.
General Aboda said all militants captured in Hawija were turned over to Iraqi military intelligence officers.
The military coalition in Hawija included Iranian-trained militiamen, federal police officers and local Sunni tribal fighters. They were backed by American airstrikes and artillery.
Mr. Hawas and other Sunni residents complained about the Kurdish fighters known as pesh merga, who maintained defensive lines a few miles north of the city. They said the overwhelming vote last month for independence from Iraq for the Kurdish autonomous region had undercut the fight against the Islamic State. The Kurds should annul the vote, many said.
There are fears that Iraqi forces will clash with pesh merga fighters now that the two sides' front lines are closer after the fall of Hawija. Kurdish leaders and the government in Baghdad are locked in a tense confrontation over the vote, with Iraq threatening military and economic reprisals if the Kurds don't annul the results.
"If they insist on their independence, then of course we may have to fight them," General Aboda said. But he added that the police had been ordered by Baghdad to avoid any confrontation with Kurdish fighters.
"They told us not to provoke anything," said another police commander in Hawija, Gen. Maitham al-Abbodi.
Despite the military triumph, not everyone was so sanguine about the end of Islamic State. Col. Kareem Aboud of a federal police SWAT unit, who was providing security for food deliveries to displaced Hawija district residents, said he was not convinced that the Islamic State was on the verge of complete defeat in Iraq.
"They're like a cancer," he said. "You can never declare them dead."
Falih Hassan contributed reporting from Hawija, and Rod Nordland from Dibis, Iraq.