Forces aligned to Libya’s UN-backed national unity government have gained full control of Sirte after months of fighting, in a major blow to the Islamic State of Iraq and the Levant (ISIL) group in the country.

“Our forces have total control of Sirte,” Reda Issa, a spokesman for pro-government forces, told AFP news agency on Monday. “Our forces saw Daesh totally collapse,” he said referring to the Arabic name of ISIL.

The battle for the coastal city, which was the last significant territory held by ISIL, also known as ISIS, in Libya, cost the lives of hundreds of loyalist troops as well as an unknown number of ISIL fighters, Issa said.

In Pictures: Embedded with the Libyan forces fighting ISIL in Sirte

The government forces seized the coastal city’s Jiza al-Bahrieh district, the last area where the armed group has been holding out, and were in the process of securing it, Issa said in a separate interview with DPA news agency.

“Daesh has totally collapsed and dozens of them have given themselves up to our forces,” said a statement on the loyalist forces’ official Facebook page.

ISIL fighters are still thought to be present in several parts of southern and eastern Libya but no longer control any towns.

Al Jazeera’s Mahmoud Abdelwahed, reporting from Sirte, said that there are still a few ISIL fighters holding out.

“The fighting has been going on all day,” he said, adding that at least 30 ISIL fighters have surrendered to the pro-government forces.

The question now is, how many of the fighters have fled to other parts of Libya, Anas El Gomati, director of the Tripoli-based Sadeq Institute, said in an interview with Al Jazeera from Dakar, Senegal.

“The fear now is that if ISIS moves into other parts of Libya, does it induce more and more conflict?” he said.

Children being treated for their injuries at a hospital in Misrata, north of Sirte [Reuters]

Divided country

The developments follow a bitter seven-month campaign against ISIL, which took advantage of Libya’s split between rival governments in the east and west of the country to build up its largest territory outside of its heartland in Syria and Iraq.

Akram Glawan, Misrata Hospital spokesman, told AP news agency that 711 Libyan fighters have been killed battling ISIL during the seven-month operation in Sirte and that another 3,200 have been wounded.

Despite the apparent victory in Sirte, Libya remains deeply divided, with the national unity government based in the capital Tripoli unable to gain recognition from the elected parliament based in the eastern city of Tobruk.

Forces loyal to Tobruk military strongman General Khalifa Haftar have made major advances in recent months, seizing the country’s critical oil ports from forces aligned to the unity government.

Analysts argue that Haftar’s growing strength means that the UN-backed deal setting up the national unity government is increasingly out of step with the balance of power on the ground and should be revisited.

Even in Tripoli the unity government’s rule is far from secure, with a third rival administration backed by hardline armed groups recently attempting a comeback.

Clashes between rival militias claimed at least four lives in the city on Friday, according to the al-Wasat news site.