Sirte, some 450 kilometres east of the capital Tripoli, had been held since 2016 by forces allied with the UN-recognised Government of National Accord.
Libyan warlord Khalifa Haftar's militia on Monday seized the coastal city of Sirte from the UN-backed government, raising tensions as Turkey said it was deploying troops in the North African country.
Sirte, some 450 kilometres east of the capital Tripoli, had been held since 2016 by forces allied with the UN-recognised Government of National Accord (GNA).
But on Monday, a spokesman for the GNA, said the city had fallen to Haftar's militia.
Haftar's militia confirmed it by saying the city had fallen to their fighters.
"Sirte has been totally liberated," Haftar's spokesperson Ahmad al Mesmari announced on television.
"The operation was quick and lasted only three hours," Mesmari said, although preparations had started months earlier with air strikes on positions of pro-GNA forces.
He said Haftar loyalists struck from five land and sea positions and had air cover. He did not give further details.
The oil-rich North African country has been plunged into chaos since the 2011 NATO-backed uprising that killed longtime leader Muammar Gaddafi.
It is now divided between the GNA based in the capital Tripoli and Haftar's militia in the east and which also control most of the country's south.
Tensions escalated last year when Haftar launched an operation in January to "purge" southern Libya "of terrorist groups and criminals" and seized several towns with support from some local tribes.
Haftar then set his eyes on Tripoli, launching an offensive on the capital in April to unseat the GNA.
The GNA has sought help from Turkey, whose parliament passed a bill allowing the government to send troops to Libya to shore up the Tripoli government.
On Sunday, Turkey's President Recep Tayyip Erdogan announced that Turkish soldiers had begun deploying in Libya.
Fears of escalation
Although there has been no immediate confirmation from Tripoli of that deployment, Turkey's involvement has raised concern among Libya's neighbours and in Europe.
Egypt said it will hold a meeting on Wednesday with the foreign ministers of France, Italy, Greece and Cyprus for talks on "ways to push efforts to reach a comprehensive settlement" in Libya.
Algeria, which on Monday hosted GNA prime minister Fayez al Sarraj as well as Turkish Foreign Minister Mevlut Cavusoglu, urged the UN Security Council to impose a ceasefire in Libya.
The European Union, for its part, expressed concern over an "imminent" escalation of violence around Tripoli.
While the GNA is backed by Turkey and Qatar, Haftar has the support of Egypt, the United Arab Emirates and Russia.
On Friday, Haftar urged all Libyans to take up arms in response to any Turkish involvement in his country.
Sirte was at one stage a bastion of the Daesh which moved into Libya amid the chaos that followed Gaddafi's ouster.
Daesh controlled Sirte from early 2015 until the GNA, backed by US air strikes, evicted the militants in a seven-month battle that cost hundreds of lives.
Haftar's militia earlier Monday said on social media they were "steadily advancing towards the heart of Sirte" after seizing control of Ghardabiya airport on the outskirts.
It said forces at the airport surrendered with their equipment and reported clashes in several parts of Sirte.
Pro-GNA forces said in a Facebook post they had come under attack in Sirte and that mercenaries from Chad were fighting alongside the militia.