MOSUL/ERBIL, Iraq (Reuters) - After eight months of grinding urban warfare, Iraqi government troops on Thursday captured the ruined mosque at the heart of Islamic State’s de facto capital Mosul, and the prime minister declared the group’s self-styled caliphate at an end.

Iraqi authorities expect the long battle for Mosul to end in coming days as remaining Islamic State fighters are bottled up in just a handful of neighborhoods of the Old City.

The seizure of the nearly 850-year-old Grand al-Nuri Mosque -- from where Islamic State proclaimed the caliphate nearly three years ago to the day -- is a huge symbolic victory.

“The return of al-Nuri Mosque and al-Hadba minaret to the fold of the nation marks the end of the Daesh state of falsehood,” Prime Minister Haider al-Abadi said in a statement, referring to the hardline Sunni Mulsim group by an Arabic acronym.

The fall of Mosul would in effect mark the end of the Iraqi half of the IS caliphate, although the group still controls territory west and south of the city, ruling over hundreds of thousands of people.

Its stronghold in Syria, Raqqa, is also close to falling.

A U.S.-backed Kurdish-led coalition besieging Raqqa on Thursday fully encircled it after closing the militants’ last way out from the south, the Syrian Observatory for Human Rights monitoring group said.

These setbacks have reduced Islamic State’s territory by 60 percent from its peak two years ago and its revenue by 80 percent, to just $16 million a month, said IHS Markit.

“Their fictitious state has fallen,” an Iraqi military spokesman, Brigadier General Yahya Rasool, told state TV.

However, it still occupies an area as big as Belgium, across Iraq and Syria, according to IHS Markit, an analytics firm.

Islamic State fighters blew up the medieval mosque and its famed leaning minaret a week ago as U.S.-backed Iraqi forces started a push in its direction. Their black flag had been flying from al-Hadba (The Hunchback) minaret since June 2014.

Much of the mosque and brickwork minaret was reduced to rubble, said a Reuters TV reporter who went to the site with the elite units that captured it.

Only the stump of the Hunchback remained, and a green dome of the mosque supported by a few pillars which resisted the blast, he said.

The mosque grounds were off limits as the insurgents are suspected to have planted booby traps.

Abadi “issued instructions to bring the battle to its conclusion,” by capturing the remaining parts of the Old City, his office said.

The cost of the fighting has been enormous. In addition to military casualties, thousands of civilians are estimated to have been killed.

About 900,000 people, nearly half the pre-war population of the northern city, have fled, mostly taking refuge in camps or with relatives and friends, according to aid groups.

Slideshow ( 13 images )

Those trapped in the city suffered hunger, deprivation and IS oppression as well as death or injury, and many buildings have been ruined.

ARDUOUS TASK

Counter Terrorism Service (CTS) troops captured the al-Nuri Mosque’s ground in a “lightning operation” on Thursday, a commander of the U.S.-trained elite units told state TV.

CTS units are now in control of the mosque area and the al-Hadba and Sirjkhana neighborhoods and they are still advancing, a military statement said.

Slideshow ( 13 images )

Other government units, from the army and police, were closing in from other directions.

An elite Interior Ministry unit said it freed about 20 children believed to belong to Yazidi and other minorities persecuted by the jihadists in a quarter north of the Old City which houses Mosul’s main hospitals.

A U.S.-led international coalition is providing air and ground support to the Iraqi forces fighting through the Old City’s maze of narrow alleyways.

But the advance remains arduous as IS fighters are dug in the middle of civilians, using mortar fire, snipers, booby traps and suicide bombers to defend their last redoubt.

The military estimated up to 350 militants were still in the Old City last week but many have been killed since.

They are besieged in one sq km (0.4 square mile) making up less than 40 percent of the Old City and less than one percent of the total area of Mosul, the largest urban center over which they held sway in both Iraq and Syria.

Those residents who have escaped the Old City say many of the civilians trapped behind IS lines -- put last week at 50,000 by the Iraqi military -- are in a desperate situation with little food, water or medicines.

“Boys and girls who have managed to escape show signs of moderate malnutrition and carry psychosocial scars,” the United Nations Children’s Fund UNICEF said in a statement.

Thousands of children remain at risk in Mosul, it said.

IS leader Abu Bakr al-Baghdadi proclaimed himself ruler of all Muslims from the Grand al-Nuri Mosque’s pulpit on July 4, 2014, after the insurgents overran swathes of Iraq and Syria.

His speech from the mosque was the first time he revealed himself to the world and the footage broadcast then is to this day the only video recording of him as “caliph”.

He has left the fighting in Mosul to local commanders and is believed to be hiding in the border area between Iraq and Syria, according to U.S. and Iraqi military sources.

The mosque was named after Nuruddin al‑Zanki, a noble who fought the early Crusaders from a fiefdom that covered territory in modern-day Turkey, Syria and Iraq. It was built in 1172-73, shortly before his death, and housed an Islamic school.

The Old City’s stone buildings date mostly from the medieval period. They include market stalls, a few mosques and churches, and small houses built and rebuilt on top of each other over the ages.