Updated

Iraq on Monday declared "total victory" over the Islamic State group in Mosul, retaking full control of the country's second-largest city three years after it was seized by extremists bent on building a global caliphate.

"This great feast day crowned the victories of the fighters and the Iraqis for the past three years," said Prime Minister Haider al-Abadi, flanked by his senior military leadership at a small base on the edge of the Old City, where the final battles for Mosul unfolded.

Al-Abadi alluded to the brutality of the battle for Mosul — Iraq's longest yet in the fight against IS — saying the triumph had been achieved "by the blood of our martyrs."

While Mosul fell to IS in a matter of days in 2014, the campaign to retake the city lasted nearly nine months. The fight, closely backed by airstrikes from the U.S.-led coalition, brought an end to the extremists' so-called territorial caliphate, but has also left thousands dead, entire neighborhoods in ruins and nearly 900,000 displaced from their homes.

Shortly after al-Abadi's speech, the coalition congratulated him on the victory but noted that parts of the Old City still "must be back-cleared of explosive devices and possible ISIS fighters in hiding." ISIS, ISIL and Daesh are alternative acronyms for the Islamic State group.

"The victory in Mosul, a city where ISIS once proclaimed its so-called 'caliphate,' signals that its days in Iraq and Syria are numbered," President Donald Trump said in a statement.

Earlier in the day, airstrikes pounded the last IS-held territory on the western edge of the Tigris, Humvees rushed wounded to field hospitals and soldiers hurriedly filled bags with hand grenades to ferry to the front.

Iraqi troops had slowly pushed through the narrow alleys of the Old City during the past week, punching holes through walls and demolishing houses to carve supply routes and fighting positions in a district where many of the buildings date back centuries.

For days, the remaining few hundred militants held an area measuring less than a square kilometer (less than half a square mile), and Iraqi commanders described victory as imminent.

Al-Abadi also visited Mosul on Sunday, congratulating the troops on recent gains but stopping short of declaring an outright victory as clashes continued.

The drawn-out endgame in Iraq's fight for Mosul highlighted the resilience of the extremists and the continued reliance of Iraqi forces on air support to retake territory.

Iraqi commanders said gains slowed to a crawl in recent days as IS fighters used their families — including women and children — as human shields. As the battle space constricted, the coalition began approving airstrikes dropping bombs of 200 pounds or more on IS targets within 50 meters (yards) of friendly forces.

Plumes of smoke Monday grew larger than the strip of territory under IS control.

"This used to be a beautiful city, tourists used to come here," said Iraqi army Capt. Marwan Hadi based inside the Old City. The last days of the fight for Mosul were the fiercest, he said.

"All along the front line, there are so many families under the rubble," he said. "I saved two children and their mother, but one daughter, we couldn't reach her."

Reports of civilian casualties spiked as Iraqi forces punched into Mosul's western half in February. Residents fleeing the fighting reported that entire families sheltering in the basements of their homes were killed by airstrikes targeting small teams of IS fighters.

Thousands of civilians were estimated to have been killed in the fight for Mosul, according to Nineveh's provincial council. A toll that does not include those still believed buried under collapsed buildings.

Also Monday, the United Nations said there was no end in sight to the humanitarian crisis in Iraq despite the conclusion of the fighting. Of the more than 897,000 people displaced from Mosul, the U.N. said thousands of residents will probably not be able to return to the city because of "extensive damage caused during the conflict."

The infrastructure in western Mosul, where the fighting was fiercest, has been decimated. Iraq's civil defense rescue teams — a branch of the Interior Ministry — said about 65 percent of the buildings in the Old City were severely damaged or destroyed. In other western neighborhoods, destruction was estimated to be higher: some 70 percent of all houses, buildings and infrastructure.

"Daesh, when they came to Iraq, their goal was to destroy everything," said Hisham Hatem, an officer with the federal police stationed at Mosul's main hospital complex, a series of buildings that was shredded by weeks of artillery and airstrikes. Hatem said IS used tactics to draw out the fight for Mosul to ensure little of the city would be left after the group's defeat.

Regardless of the victory's heavy toll, a number of celebrations broke out across Mosul's east and west as victory appeared imminent.

Iraq's special forces held a flag-raising ceremony on the Tigris river bank and Iraqi army soldiers danced and sang to patriotic music Sunday.

Muhammad Abdul Abbas, a 20-year-old solider sat on the sidelines of the revelry. He said he was happy the fight was over, but explained that his unit, like many others, suffered significant losses. Over the past nine months, 15 of his close friends were killed fighting for Mosul, he said.

Iraq's special forces, who largely led many of the assaults in Mosul, faced casualty rates of 40 percent, according to a report in May from the office of the U.S. secretary of defense.

"Honestly, all this death and all this destruction — I don't believe it was worth it," Abbas said.

___

Associated Press writer Salar Salim in Mosul contributed to this report.