The United States has shut its embassy in Libya and evacuated its diplomats to neighbouring Tunisia under US military escort after fighting intensified between rival militias in the capital's streets, the State Department said.

"Due to the ongoing violence resulting from clashes between Libyan militias in the immediate vicinity of the US Embassy in Tripoli, we have temporarily relocated all of our personnel out of Libya," State Department spokeswoman Marie Harf said on Saturday.

Many military-grade weapons remain in the hands of private individuals, including anti-aircraft weapons that may be used against civilian aviation. US State Department

"Securing our facilities and ensuring the safety of our personnel are top department priorities, and we did not make this decision lightly," Harf said.

Speaking in Paris, US Secretary of State John Kerry said that "free-wheeling militia violence" had become a real risk to US staff as clashes erupted around the embassy.

He said Washington was suspending current diplomatic activities at the embassy but not closing it.

The evacuation was accompanied by the release of a new State Department travel warning for Libya urging Americans not to go to the country and recommending that those already there leave immediately.

"The Libyan government has not been able to adequately build its military and police forces and improve security,'' it said.

"Many military-grade weapons remain in the hands of private individuals, including anti-aircraft weapons that may be used against civilian aviation."

Britain's foreign office on Saturday also urged British nationals to leave by commercial means, due to "ongoing and greater intensity fighting in Tripoli and wider instability throughout Libya."

Weeks of violence

American personnel at the Tripoli embassy, which had already been operating with limited staffing, left the capital around dawn and traveled by road to neighbouring Tunisia, according to Harf.

The move marks the second time in a little more than three years that Washington has closed its embassy in Libya.

In February 2011, the embassy suspended operations amid the uprising that eventually toppled longtime leader Muammar Gaddafi. After the formation of a transitional government in July 2011, the embassy reopened in September.

The Obama administration has been particularly sensitive about security of US government employees in Libya since the September 11, 2012, attack on the US mission in the country's second largest city of Benghazi that killed ambassador Chris Stevens and three other Americans.

Tripoli has been embroiled for weeks in inter-militia violence that has killed and wounded dozens on all sides. The fighting has been particularly intense at the city's airport.

The US is just latest in a number of countries to have closed down their diplomatic operations in Libya. Turkey on Friday announced that it had closed down its embassy and militia clashes in Benghazi have prompted the United Nations, aid groups and foreign envoys to leave.