The US embassy in Tripoli staged a dramatic evacuation in the early hours of Saturday, with other embassies debating whether to follow suit as Libya hovers on the brink of full-scale war. Efforts by diplomats and prime minister Abdullah al-Thinni to engineer a last-minute ceasefire between warring militias have collapsed and the capital echoes to the sound of artillery and rockets.

Fighting is also continuing in the eastern city of Benghazi, part of a nation-wide struggle between an Islamist-led alliance and fragmented opposition.

In Tripoli, thousands are fleeing their homes under a rain of rocket, tank and mortar fire. "They phoned us to tell us to get out," said Huda, a resident in the south-western Tripoli district of Seraj. "They told us: you have seen how the airport looks, this will be your district too."

There are no accurate casualty figures because different militias take their wounded to their own hospitals, but estimates claim that more than 100 have died in two weeks of fighting. The health ministry said it had lost contact with its hospitals.

Tripoli's airport is a smashed ruin after two weeks of attacks on it by a militia from Misrata against another from Zintan, which has held it since the 2011 Arab spring uprising that toppled Muammar Gaddafi. In that uprising, Misrata, 120 miles west of Tripoli and Zintan, 90 miles south, were allies, forming the two most powerful militias which liberated the capital, backed by Nato bombing. Now they are at war.

Misratan brigades are determined to capture the airport, a valuable strategic asset. But the bombardment has reduced much of it to rubble. The main building is wrecked, the control tower holed and on the scorched tarmac are the remains of 21 planes – much of Libya's small commercial fleet. Three volunteer pilots flew surviving jets to Malta last week.

They may not be back for a long time. International authorities have ordered Libyan airspace to be closed on Monday and there is a last-minute scramble by foreigners and Libyans to get out. Many are streaming towards the Tunisian border crossing, with Egypt having already closed its own frontier after 21 of its border guards were killed in an ambush.

The US embassy found itself in the middle of the battle, its position close to the airport road marking the frontline between the two sides. For two weeks its staff hunkered down in concrete bunkers, protected by 90 heavily armed marines. Two rockets landed outside the walls, but the embassy compound itself took no hits. Each night drones and an Orion surveillance aircraft flew low over the city.

Ambassador Deborah Jones tweeted that there were no armed drones. But armed jets linger off the coast, with an aircraft carrier stationedover the horizon and back-up Marines deployed in Sicily.

On Friday, after consultations with Washington, the order was given to pull out. Through the early hours, the sky echoed with the sounds of planes leaving. Memories are still fresh of the fate of the last ambassador, Chris Stevens, who died along with three staff when the US consulate in Benghazi was stormed by a militia two years ago. London has said nonessential staff have been evacuated and a final decision is expected to be taken by EU embassies on whether to evacuate over the next few days.

The Americans leave a city on edge. Petrol shortages have left the streets mostly empty, but on Friday night thousands gathered for a peace rally in the central Algiers Square. Amid elegant Italian-era buildings and palm trees, they chanted "Libya Hoara!" (Libya Free!) and called for all sides to stop fighting.

"This is not what I fought the revolution for," said Mohammed, a student who joined the rebels during the 2011 uprising. "We fought for peace, and instead we get this."

In truth, the fighting never went away. The former general national congress, instead of disarming the revolutionary militias funded them and gave them official status. In June a new parliament, the House of Representatives, was elected and is due to start work next month in Benghazi, triggering a jostling for position among the militias that threatens all-out war.

"I have been saying it all along: it has to get worse before it gets better," said Sami Zaptia, editor of the Libya Herald newspaper. The question all Libyans are asking is how much worse it will get.