There were joyous scenes in Raqqa as the black Islamic State flags that have flown over the city for over three years were ripped down and replaced with bright yellow and green banners. Militia fighters and commanders clasped their arms round each other, singing and dancing in a battle-scarred public square.

Raqqa liberated
Raqqa liberated
Raqqa liberated
Syrian Democratic Forces fighters fly SDF and Kurdish flags at Al-Naim square in Raqqa

The Syrian Democratic Forces (SDF) have announced they have defeated Isis (Daesh) in its former capital after a four-month battle. A formal declaration of victory in Raqqa will soon be made once the city has been cleared of mines and any possible jihadist sleeper cells, said Talal Silo, SDF spokesman.

The fall of Raqqa, where Isis staged euphoric parades after its string of lightning victories in 2014, is a potent symbol of the movement's collapsing fortunes. Isis has lost most of its territory in Syria and Iraq this year, including its most prized possession, Mosul. In Syria, it has been forced back into a strip of the Euphrates valley and surrounding desert.

The final SDF assault began on Sunday (15 October) after a group of Syrian jihadists quit the city under a deal with tribal elders, leaving only a hardcore of up to 300 mostly foreign fighters holed up in a hospital and a stadium.

On Monday, the SDF captured "Paradise Square," Raqqa's infamous public square that was used by the militants to perform beheadings and other killings in front of residents who were summoned by loudspeakers and forced to watch. Bodies and severed heads would be displayed there for days, mounted on posts and labeled with their crimes, according to residents, who later dubbed it "Hell Square."

The SDF captured the hospital in fierce fighting overnight and early on Tuesday. Under Isis, the facility had served as both a hospital and a command centre.

Dozens of militants made their last stand in the stadium, which the group had turned into a notorious prison in the more than three years it held the city. Rojda Felat, commander of the Raqqa campaign, said the fighting was over on Tuesday afternoon (17 October) and the SDF just had to clear the last few militants out of the stadium.

The fight for Raqqa has shattered much of the city. Houses, apartment blocks and public buildings were flattened by air strikes or holed by shellfire. The international charity Save the Children said many of the 270,000 people who fled the fighting would likely be stuck in aid camps for months or years. Children who fled are haunted by nightmares from the violence they witnessed, including Islamic State beheadings and coalition airstrikes, it said.