By Jonathan Beale- Defence Correspondent, Mosul
Even while the Iraqi prime minister was on his way to Mosul to declare the liberation of the city, there was still the occasional sound of gunfire and coalition warplanes flying overhead.
Earlier in the morning we saw a number of airstrikes in the Old City. Iraqi forces were still pinned down by snipers from the group that calls itself Islamic State.
Colonel Jabbar Abad told us it was the last pocket of resistance. He claimed they would be defeated within hours.
His troops helped a steady stream of civilians fleeing to safety. Mostly women and children. Their faces were haunted and some had to be helped.
The children didn’t even flinch when there was more sound of gunfire. An older woman was so weak she could barely walk. A few babies being carried looked almost lifeless.
The families were given food and water. This, their first taste of freedom after three years of living under IS control. The battle briefly forgotten in their own fight for survival.
If this is victory it has come at a huge cost. Not just in human life. Nearly everyone rescued had to leave dead relatives behind.
Almost every building in the old city has been scarred or completely destroyed.
Media caption’The is still a lot of misery in Mosul’
Search and rescue teams are still pulling bodies from the rubble. The heat has contributed to the stench of decaying corpses.
We met Ali, who had come to find his brother’s family. Hoping against hope that some may have survived.
He said IS fighters had been using their house when it was hit by a coalition airstrike a few weeks ago. Iraqi security forces had only recently taken the area.
With tears streaming down his face, Ali held up his mobile phone and told me he’d spoken to his brother trapped under the rubble. But over the last few days there had been no reply.
Ali helped the search and rescue teams make their way through the tonnes of rubble.
They tried to console him when all they could find was what must have been their remains, which they carried off in a black zipped bag. We watched them do the same at several other sites.
Contrast that with the jubilation of the Iraqi security forces who mobbed Prime Minister Abadi as he arrived in the city to declare victory over IS.
This is still a significant moment. The extremists have held the city for three years. It’s taken nine months of brutal street to street fighting to dislodge them.
This was their stronghold in Iraq. It was here, in the city’s now flattened Great Mosque of al-Nuri, where their leader, Abu Bakr al-Baghdadi, made his one and only public appearance as Caliph of their so-called state.
For many IS fighters Mosul is their graveyard, though it is still likely that some have escaped.
The misery of Mosul is far from over. The UN estimates it will cost at least $1bn (£0.77bn) to restore the city’s basic infrastructure – such as clean water and electricity.
It will take tens of billions more to rebuild this city.