Western countries urged their citizens to leave Libya yesterday, as the country descended further into civil war and British diplomats came under fire.

As fighting raged across the country leaving 59 dead, Britain warned against travel to Libya, and told those already there to leave. "British nationals in Libya should leave now by commercial means," the Foreign Office said. Britain's embassy would remain open but with reduced staff.

France, Germany and the Netherlands issued similar warnings. "The situation is extremely unpredictable and uncertain," the German foreign ministry said. "German nationals are at increased risk of kidnapping and attacks."

Earlier on Sunday, a vehicle carrying a British diplomat was ambushed and sprayed with gunfire on the outskirts of Tripoli.

The armoured vehicle was evacuating British diplomats to neighbouring Tunisia and was attacked close to Camp 27, the base of an Islamist militia on the western outskirts.

Gunmen fired four rounds, all of them stopped by bullet-proof glass, and the vehicle, a white 4x4 with red diplomatic plates, was able to speed away. Ambassador Michael Aron later tweeted: "Shots were fired at our vehicles but all staff safe."

British security officers then warned a second convoy that was evacuating EU staff on the same coastal highway and it turned back, some of the staff later leaving Tripoli on an Italian air force transport plane.

On Saturday, the United States embassy had evacuated staff in the early hours of morning along the same road, with US jets orbiting above ready to strike militia. The decision had been taken after consultations with Washington. 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.

With the American exit, the international community has more or less given up on a diplomatic solution. The Italian air force said it stood ready for more airlifts but EU ambassadors holding a crisis meeting on Sunday said no final decision on a total pullout had been reached.

Such an evacuation would be a severe loss of face, particularly for London and Paris, which led the Nato bombing of Gaddafi three years go and proclaimed at the time they had delivered democracy to Libya.

At Mitiga airport on Sunday waiting for the Italian air force flight, one foreign official said apportioning blame for why it all went wrong must wait for another time. "Today the priority is getting out."

Those evacuating leave behind a city in turmoil. For two weeks Tripoli has echoed to the drumbeat of artillery, tank fire and rockets as rival militias trade fire, much of it landing on innocent civilians. One rocket strike on a house killed 23 Egyptian workers on Sunday, and thousands more are fleeing their homes.

Similar scenes are taking place in the eastern capital, Benghazi, where air force jets allied with a former general, Khalifa Hiftar, pounded Islamist militia bases in battles that left 36 dead.

The battles are part of a wider struggle between Islamists and their opponents, triggered by elections in late June for a new parliament, the house of representatives, that saw steep losses for Islamist parties.

Those parties, including the Muslim Brotherhood's Justice and Construction party, will almost certainly lose control of the legislature, and their militias fear they will be dissolved.

In Tripoli, an alliance of Islamist and Misratan militias is focused on dominating the city and ejecting a militia from Zintan, which is allied with Hiftar.

The Zintanis hold the airport and a wedge-shaped area in the south and west, all of it now the scene of ferocious violence. Rockets and artillery are directed at the airport and half a dozen districts, with the Zintanis replying in kind. But much of the firing is wild, hitting homes and apartments.

Petrol is scarce, power is more off than on and the internet has been cut. In the absence of security forces, anarchy has broken out. Several banks have been raided by gangs armed with anti-tank rockets, blowing open safes to steal millions of dinars, and kidnappings are rampant.

Tripoli's main medical warehouse has been ransacked by one militia group, leaving hospitals running out of drugs at a time when they most need them.

Seraj, a hotel worker, said he drove from hospital to hospital looking for drugs for his friend, each time being told they had run out. "We tried four hospitals, all give the same answer, no drugs. I can't go to more hospitals, there is no petrol."

Meanwhile, the government has collapsed. On Thursday night, the prime minister, Abdullah al Thinni, was refused permission to board his own plane and leave the city for the east, by the militia that controls Mitiga, Tripoli's second airport. The main international airport is now a battered ruin.