Iraqi Prime Minister Haider al-Abadi was set to declare victory over Islamic State in Mosul on Monday as only a few dozen militants put up resistance in the city that was the capital of their self-declared caliphate for the past three years.
Gunfire and explosions could be heard as the U.S.-led coalition pounded the remaining few Islamic State positions.
"They won't declare victory until the area if fully secured," said Iraqi army officer Firas Abdel Qassim. The militants still controlled a small patch, he said.
Abadi has been meeting military and political officials in Mosul in a festive atmosphere which contrasted with the fear that quickly spread when a few hundred Islamic State militants seized the city and the Iraqi army crumbled in July 2014.
Islamic State leader Abu Bakr al-Baghdadi shocked the Middle East and Western powers shortly afterwards by appearing at the pulpit of Mosul's Grand al-Nuri Mosque in broad daylight and declaring a caliphate and himself the leader of the world's Muslims.
A reign of terror followed which eventually alienated even fellow Sunni Muslims who supported the group, handing an advantage to the security forces.
Baghdadi has fled the city and his exact whereabouts are unknown. Reports have said he is dead but Iraqi and Western officials have not been able to confirm this.
Even if Baghdadi is killed or captured, that is unlikely to cripple Islamic State, which is now expected to take to the desert or mountains of Iraq and wage an insurgency, much like al Qaeda did following the fall of Saddam Hussein in 2003.
"The recovery of Mosul is a significant step in the fight against terrorism and violent extremism," said the spokesman for U.N. Secretary-General Antonio Guterres.
While defeat in Iraq's second-largest city will deal a heavy blow to Islamic State, the group controls several cities and towns south and west of Mosul.
Islamic State is also under heavy pressure in its operational headquarters in the Syrian city of Raqqa and its self-proclaimed caliphate that once straddled the two countries is crumbling.
The militants, however, are expected to keep plotting attacks on the West and inspiring "lone wolf" violence by individuals or small groups, such as recent incidents in Britain, France and elsewhere.
The stench of corpses along Mosul's streets was a reminder of the nearly nine months of grueling urban warfare required to dislodge Islamic State from the city of 1.5 million.
Seven bodies lay in an alley near a riverbank the militants reached on Sunday while attempting to escape.
Much of Mosul has been destroyed in the fighting, with rows of houses flattened by air strikes and centuries-old stone houses gutted by explosions.
Thousands of people have been killed. The United Nations says 920,000 civilians have fled their homes since the military campaign began in October. Close to 700,000 people are still displaced.
"It's a relief to know that the military campaign in Mosul is ending. The fighting may be over, but the humanitarian crisis is not," said U.N. Humanitarian Coordinator for Iraq Lise Grande.
"Many of the people who have fled have lost everything. They need shelter, food, health care, water, sanitation and emergency kits. The levels of trauma we are seeing are some of the highest anywhere. What people have experienced is nearly unimaginable."
Iraqi soldiers were relaxed. Some were swimming in the Tigris river. Another wiped the sweat off his face with an Islamic State flag.
Once celebrations end, Iraqi leaders will face the formidable task of managing sectarian tensions in Mosul and elsewhere that enabled Islamic State to initially win support and threaten to create new security challenges.