Libyan forces backed by US airstrikes finished clearing the last Islamic State hold-out in Sirte on Tuesday after a six-month battle for the militant group's former North African stronghold.
The forces gained full control over a final patch of ground in Sirte's Ghiza Bahriya district after fierce clashes.
Several dozen women and children who had been holed up with the militants were able to leave the ruined buildings where they had made their last stand.
As celebrations erupted among the Libyan forces, which are dominated by brigades from the city of Misrata, a spokesman said the military campaign would continue until the wider area was secured. Fighters fired in the air chanting "Free Libya" and "The blood of the martyrs was not for nothing"
The loss of Sirte is a major blow for Islamic State, leaving the group without any territory in Libya, though it retains an active presence in parts of the North African country.
The jihadist group took over Sirte in early 2015, turning it into their most important base outside the Middle East and moving large numbers of foreign fighters into the city.
It imposed its ultra-hardline rule on residents, and extended its control along about 250 km (155 miles) of Libya's Mediterranean coastline.
Spokesman Rida Issa said although forces had "secured all the buildings and the streets" in Ghiza Bahriya, this did not mean the end of the Misrata-led operation. "We still need to secure the area around Sirte," he said.
French Defence Minister Jean-Yves Le Drian said: "This is very good news. The defeat of Daesh (Islamic State) is a very strong act, but it can only be seen as a step ... the militias that have freed Sirte deserve to be congratulated."
Libyan and Western officials say some Islamic State fighters escaped from Sirte before the battle or in its early stages. They fear an insurgent campaign from outside the city and there have been attacks in outlying areas.
Bombers, Snipers and Mines
The Misrata-led forces counter-attacked in May after jihadists moved along the coast towards their city. The brigades, nominally aligned with a UN-backed government in Tripoli, advanced rapidly towards the centre of Sirte before suicide bombers, snipers and mines largely halted their progress.
More than 700 of their fighters have been killed and more than 3,200 wounded in the gruelling campaign. On Tuesday, a further three men were killed and about 50 wounded, said Mohamed Lajnef, an official at Sirte's field hospital.
He said 21 women and 31 children had been released in Ghiza Bahriya. Dozens of other women and children, some of them migrants from sub-Saharan Africa held captive by Islamic State, had escaped or had been released from militant-held ground in recent days.
Since August 1, the United States has carried out at least 495 airstrikes against Islamic State in Sirte.
Five years after the revolution that toppled Muammar Gaddafi Libya remains in turmoil.
The UN-backed Government of National Accord (GNA) that arrived in Tripoli in March and supported the campaign in Sirte has made little progress in ending the chaos.
Sirte lies in a strategic position about halfway along Libya's coastline, near some of the country's major oil fields and terminals. Close to Gaddafi's birthplace, it is the city where he was shot and killed after ruling Libya for 42 years.
Almost all of Sirte's estimated population of 80,000 fled the city since Islamic State took over.