TRIPOLI, July 26 (Reuters) - The United States evacuated its embassy in Libya on Saturday, driving diplomats across the border into Tunisia under heavy military escort after escalating clashes broke out between rival militias in Tripoli.

Security in the Libyan capital has deteriorated following two weeks of clashes between brigades of former rebel fighters who have pounded each other with rockets and artillery fire in southern Tripoli near the embassy compound.

The violence is the worst seen in Tripoli and in eastern Benghazi since the 2011 fall of Muammar Gaddafi. Western governments fear Libya is teetering toward becoming a failed state just three years after the NATO-backed war ended his one-man rule.

Three F-16 fighters provided air support and Osprey aircraft carrying Marines flew overhead the U.S. convoy as a precaution, but there were no incidents during the five-hour drive from Tripoli to Tunisia, U.S. officials said.

"Security has to come first. Regrettably, we had to take this step because the location of our embassy is in very close proximity to intense fighting and ongoing violence between armed Libyan factions," U.S. State Department spokeswoman Marie Harf said in a statement.

U.S. sources familiar with the matter said there were about eight U.S. diplomats and 200 or more U.S. security personnel in Libya and all had been evacuated.

A Reuters reporter outside the embassy later saw no sign of movement or personnel on the perimeter gate of the compound, which lies a few kilometers from the airport.

Since one militia attacked Tripoli airport two weeks ago, fighting has killed at least 50 people in the capital, shut down most international flights and forced the United Nations and Turkey to pull out their diplomatic staff.

Tripoli was quieter after the evacuation. But at least 25 people were also killed in a day of clashes between Libyan special forces and Islamist militants who are entrenched in the eastern city of Benghazi, security and hospital sources said.

Speaking to reporters in Paris before holding talks on the Middle East, U.S. Secretary of State John Kerry described Libya's situation of "free-wheeling militia violence" as a real risk to U.S. staff with clashes around the embassy.

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."

The battle for control of Tripoli International Airport is the latest eruption in a rivalry among bands of ex-fighters who once battled side by side against Gaddafi. Since then, they have turned against each other in the scramble for control.

Since the 2011 fall of Tripoli, fighters from the western town of Zintan and allies have controlled the area including the international airport, while rivals loyal to the port city of Misrata entrenched themselves in other parts of the capital.

SENSITIVE ISSUE

The State Department spokeswoman said embassy staff would return to Tripoli once it was deemed safe. Until then, embassy operations would be conducted from elsewhere in the region and Washington.

Security in Libya is an especially sensitive subject for the United States because of the Sept. 11, 2012, attack on the U.S. mission in Benghazi, in which militants killed Ambassador Chris Stevens and three other Americans.

The attack also brought political fallout for President Barack Obama, with Republicans saying his administration did not provide sufficient overall security, did not respond quickly to the attack and then tried to cover up its shortcomings.

Ed Royce, Republican chairman of the House Committee on Foreign Affairs, told CNN on Saturday the administration needed to get "more engaged on the ground with the factions in Libya" to help bring the violence under control.

"I think they're on the right track (now) but late into the game in terms of trying to bring factions together and use U.S. leverage in order to try to work this out," Royce said.

A Libyan militant suspected of involvement in the 2012 attack, Ahmed Abu Khatallah, was captured in Libya last month and brought to the United States. He has pleaded not guilty.

But three years after Gaddafi's demise, Libya's transition to democracy is faltering, and its fragile government and nascent armed forces are unable to impose authority over the brigades of former fighters.

Many ex-fighters on the government payroll as semi-official security forces, but often pay little heed to the central government, each brigade claiming to be a legitimate force and the successors of the 2011 revolution.

Heavily armed, they have sided with competing political forces vying to shape the future of Libya in the messy steps since the end of Gaddafi's four-decade rule.

Libya's Western partners fear the OPEC oil-producing country is becoming increasingly polarized between two main groupings of competing militia brigades and their political allies.

One side is grouped around Zintan and their Tripoli allies, the Qaaqaa and al-Sawaiq brigades, which are loosely tied to the National Forces Alliance political movement in the parliament.

Opposing them is a faction centered around the more Islamist-leaning Misrata brigades and allied militias who side with the Justice and Construction Party, a wing of the Muslim Brotherhood. (Additional reporting by Bill Trott and Phil Stewart in Washington, Arshad Mohammed in Paris; Editing by Gareth Jones, David Gregorio and Lisa Shumaker)

We welcome comments that advance the story through relevant opinion, anecdotes, links and data. If you see a comment that you believe is irrelevant or inappropriate, you can flag it to our editors by using the report abuse links. Views expressed in the comments do not represent those of the Thomson Reuters Foundation. For more information see our Acceptable Use Policy.

In a camp for displaced Rohingya Muslims residents frequent bamboo “internet huts” where they can communicate with relatives who left the country, escaping the violence that led to 200 deaths and left over 140,000 homeless in 2012