Iraqi Prime Minister Haidar al-Abadi formally declared victory over the Islamic State (IS) on July 10 in a speech on state television, marking the biggest defeat for the group since it declared a caliphate three years ago.
"I announce from here the end and the failure and the collapse of the terrorist state of falsehood and terrorism which the terrorist Daesh announced from Mosul," he said using an Arabic acronym for Islamic State.
Abadi, dressed in a black military uniform and flanked by commanders from the security forces, thanked the troops and the coalition. But he warned that more challenges lay ahead.
"We have another mission ahead of us, to create stability, to build and clear Daesh cells and that requires an intelligence and security effort, and the unity which enabled us to fight Daesh," he said.
U.S. President Donald Trump congratulated Iraq on defeating IS in Mosul.
"The victory in Mosul" signals Islamic State's "days in Iraq and Syria are numbered," Trump said in a statement.
The U.S.-led coalition said the loss of Mosul was a "decisive blow" against the group, but does not mark the end of the war against the militants.
"This victory alone does not eliminate [IS] and there is still a tough fight ahead. But the loss of one of its twin capitals and a jewel of their so-called caliphate is a decisive blow," Lieutenant General Stephen Townsend, the commander of the U.S.-led operation against IS, said in a statement.
Hours earlier, reporters had seen heavy fighting still under way in the city. It was not immediately clear if the clashes had ended.
Abadi visited Mosul on July 9 to congratulate the troops, even as fighting still raged nearby.
Mosul fell to the IS group in 2014, when its fighters blitzed across much of northwestern Iraq and subsequently declared a caliphate in the territory under its control in Iraq and Syria.
A 100,000-strong coalition of Iraqi government units, Kurdish Peshmerga fighters, and Shi'ite militias launched the offensive to recapture the city from the militants in October, with key air and ground support from a U.S.-led coalition.
By late January, the eastern half of the city -- which is divided by the Tigris river onto a western and eastern section -- was declared liberated.
The push into western Mosul began the following month and in June Iraqi forces started the weeks-long push through the Old City, Mosul's most congested district.
In recent days, they had confined the remaining few hundred IS militants in an area measuring less than a square kilometer.
Much of Mosul has been destroyed in the fighting, with rows of houses flattened by air strikes, and 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.
The defeat in Iraq's second-largest city will deal a heavy blow to IS, but the group still controls several cities and towns south and west of Mosul.
Islamic State is also under heavy pressure in its operational stronghold in the Syrian city of Raqqa.