Displaced Iraqis walk past the ruins of the Nuri mosque in the Old City of Mosul on June 30, 2017

Iraq will declare victory over the Islamic State group in Mosul during the "next few days," a senior commander said Friday, as the jihadists fell back in neighbouring Syria.

IS, which declared a cross-border "caliphate" encompassing swathes of Iraq and Syria three years ago, is now facing twin offensives in Mosul and Raqa, its two most emblematic strongholds.

But while the loss of the two cities would be a major blow to IS, it would not mark the end of the threat posed by the group, which is likely to return to insurgent-style attacks that were its hallmark in years past.

"In the next few days, we will announce the final victory over Daesh," Staff Lieutenant General Abdulghani al-Assadi, a senior commander in the elite Counter-Terrorism Service, told AFP in Mosul, using an Arabic acronym for IS.

The retreat of Islamic State group

However, there has often been a gap between the declaration of victory and the actual end of fighting in a given area in the course of Iraq's multi-year war against IS.

Iraqi forces launched the gruelling battle for Mosul on October 17, advancing to the city and retaking its eastern side before setting their sights on the smaller but more densely populated west, where IS still holds limited territory.

Assadi estimated that there are between 200 and 300 IS fighters left in the city, most of them foreigners.

His remarks on victory in Mosul came as IS withdrew from a series of villages in Syria's Aleppo province where President Bashar al-Assad's forces are advancing.

"IS withdrew from 17 towns and villages and is now effectively outside of Aleppo province after having a presence there for four years," said Rami Abdel Rahman, head of the Syrian Observatory for Human Rights.

Regime forces had been advancing through a sliver of southeastern Aleppo province around a key highway linking Hama province to the southwest and Raqa province further east.

A Syrian military source in rural Aleppo confirmed the withdrawal.

- IS escape route cut -

"The military operation is ongoing and Daesh withdrew from the Aleppan countryside towards rural territory in Hama and Raqa," the source told AFP.

The US-backed Syrian Democratic Forces (SDF) are also fighting to retake Raqa, IS's de facto capital in the country.

On Thursday, they cut off IS's last escape route, trapping the jihadists inside the city.

"The SDF has been able to completely encircle Raqa," Abdel Rahman said.

The SDF broke into Raqa on June 6 after spending months chipping away at jihadist territory around the city.

Its fighters have since captured two eastern and two western districts of the city and are pushing towards its centre, where IS fighters are holding tens of thousands of civilians.

Around 2,500 jihadists are fighting in the city, according to British Major General Rupert Jones, a coalition deputy commander.

A member of Iraq's Counter-Terrorism Service stands next to the destroyed Nuri mosque in the Old City of Mosul

In Mosul, Iraqi forces captured the iconic Nuri mosque on Thursday, the site where IS chief Abu Bakr al-Baghdadi made his only known public appearance in 2014, calling on Muslims worldwide to obey him.

IS blew up the mosque and the famed Al-Hadba (hunchback) leaning minaret last week as Iraqi forces closed in.

Iraqi Prime Minister Haider al-Abadi hailed the recapture of the mosque as a sign of IS's impending defeat.

"We are seeing the end of the fake Daesh state," Abadi said in an English statement on his Twitter account.

The US-led coalition against the jihadists also said that the end of the battle was near.

Speaking about an announcement of Mosul's recapture, coalition spokesman Colonel Ryan Dillon said that: "I can't put a timeline on that for them, but I see it closer to days than a week or weeks."

He praised the Iraqi forces's "grit and determination" and said coalition support would help bring "an imminent liberation".

An Iraqi military vehicle drives past the ruins of the Nuri mosque in the Old City of Mosul on June 30, 2017

The end of the battle will usher in a whole new set of challenges for Iraq, including retribution against residents of the city suspected of having IS ties -- an issue highlighted by the UN rights office on Friday.

"We are seeing an alarming rise in threats, specifically of forced evictions, against those suspected of being (IS) members or whose relatives are alleged to be involved with (IS)," spokesman Rupert Colville said.