MOSULinfo-icon:  Prime Minister Haider al-Abadi joined celebrations in liberated city of Mosul Sunday after Iraqi soldiers and civilian volunteers drove Daesh from its last stronghold in a nearly nine-month long campaign.

Dressed in a black military uniform, a smiling al-Abadi walked amid the soldiers, at one point grabbing an Iraqi flag and briefly draping it on his shoulders. Other troops waved flags and pointed their weaponsinfo-icon in the air nearby.

"The Commander-in-Chief of the Armed Forces (Prime Minister) Haider al-Abadi, arrived in the liberated city of Mosul and congratulated the heroic fighters and the Iraqi people on the great victory," a statement from his office read on Sunday.

According to Iraqi sources, authorities are planning week long celebrations across the country after the formal declaration of victory in Mosul.

The recapture of Mosul, located some 400 kilometers (250 miles) north of the capital, Baghdadinfo-icon, would mark the effective end of Daesh in the Arab country.

Daesh, cornered in a shrinking area of the city, had vowed to "fight to death." The militants had resorted to sending veiled women bombers among the thousands of wounded, malnourished and fearful civilians, who were fleeing heavy clashes between government troops and the terrorists.

Al-Iraqia TVinfo-icon quoted al Abadi as saying he "congratulates the heroic fighters and the people on the big victory", even as fighting rang out in pockets near the militants' last stand at the Tigris River.

The loss of the city would mark a decisive defeat for Daesh or Islamic Stateinfo-icon group, which had surfaced in Mosul in the summer of 2014 and declared the ancient city as the capital of its caliphate.

When Daesh seized Mosul, Iraqinfo-icon's second-largest city, in the summer of 2014 they swept across northern and central Iraq. Group's leader, Abu Bakr al-Baghdadi had then appeared at Mosul's al-Nuri Mosque and declared a caliphate on territory it seized in Iraq and Syriainfo-icon.

Iraq launched the operation to retake Mosul in October, backed by airstrikes from the USinfo-icon-led coalition. The fierce battle has killed thousands and displaced more than 897,000 people.

Last month, as Iraqi troops closed in on Mosul's Old City, the militants destroyed the al-Nuri Mosque and its famous leaning minaret to deny the forces a symbolic triumph.

Lt. Gen. Jassim Nizal of the armyinfo-icon's 9th Division said his forces achieved "victory" in their sector, after a similar announcement by the militarized Federal Police. His soldiers danced to patriotic musicinfo-icon atop tanks even as airstrikes sent up plumes of smoke nearby.

Nizal acknowledged that many of his men were among those who fled the city when IS forces seized Mosul in 2014 in a humiliating defeat for the Iraqi armed forces.

"Some things happened here, that's true," he said. "But we have come back."

Much of the Old City and surrounding areas have been devastated by the grueling urban combat. On Sunday, a line of weary civilians walked out of the Old City, past the shells of destroyed apartment blocks lining the cratered roads.

In the run-up to the liberation of Mosul, Iraqi army soldiers and volunteer fighters from the Popular Mobilization Units, commonly known by their Arabic name, Hashd al-Sha'abi, had made sweeping gains against Daesh since launching the Mosul operation on October 17, 2016.

The Iraqi forces took control of eastern Mosul in January after 100 days of fighting, and launched the battle in the west on February 19.

An estimated 862,000 people have been displaced from Mosul ever since the battle to retake the city began eight months ago. A total of 195,000 civilians have also returned, mainly to the liberated areas of eastern Mosul.