The State Department on Saturday evacuated all U.S. personnel from its embassy in Libya after clashes among rival militias in the capital intensified in recent days in the vicinity of the diplomatic mission, officials said.

Traveling in Paris, Secretary of State John F. Kerry cited the threat posed by “freewheeling militia violence” near the embassy in Tripoli. Kerry said some embassy functions will continue from neighboring Tunisia, where diplomats were taken.

“We will return the moment the security situation permits us to,” Kerry said.

The evacuation of diplomats and other government personnel by land lasted five hours and was carried out with U.S. military aircraft providing security from the air, officials said. The decision was not made lightly, the State Department said.

“Security has to come first,” spokeswoman Marie Harf said in a statement. “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.”

Black plumes of smoke is seen in the vicinity of Camp Thunderbolt, after clashes between militants, former rebel fighters and government forces in Benghazi July 26, 2014. (Esam Omran Al-Fetori/Reuters)

When U.S. diplomats evacuate a diplomatic post, they must smash computers and other sensitive equipment that could be exploited for intelligence purposes.

The State Department also issued a new travel warning for U.S. citizens, advising against all travel to the country and recommending that Americans in Libya leave now.

“The security situation in Libya remains unpredictable and unstable,” the department said in its warning notice. “The Libyan government has not been able to adequately build its military and police forces and improve security following the 2011 revolution.”

Saturday’s closure of the embassy in Tripoli marked the second time the State Department has shuttered its Libya mission since 2011, when U.S. personnel left as the country’s civil war broke out.

The decision was rich in symbolism, coming less than two years after militants in the eastern city of Benghazi stormed two U.S. government compounds, killing the American ambassador, J. Christopher Stevens, and three of his colleagues.

Since that attack, which ignited a political firestorm, the Obama administration has bolstered security measures for its diplomats in Libya and has sought to take steps to stabilize the oil-rich nation reeling from decades of despotic rule.

The evacuation drew a mixed response from Rep. Edward R. Royce (R-Calif.), chairman of the House Foreign Affairs Committee, who said it “seems like the right call” given the chaotic security situation in Libya, but added that it also reflected a lack of direction on the administration’s part.

“Our diplomatic absence will make the hard task of achieving political stability in Libya even harder,” Royce said.

In the State Department statement, Harf characterized the evacuation as “temporary” but provided no time frame for a possible return.

Rear Adm. John Kirby, a Pentagon spokesman, said the U.S. military provided F-16 planes, surveillance aircraft and an airborne response force with MV-22 Osprey aircraft.

“The mission was conducted without incident,” he said.

In recent weeks, fighting has spread to Tripoli’s airport, compromising the easiest evacuation route for U.S. personnel. The U.S. ambassador in Tripoli, Deborah K. Jones, conveyed on Twitter how tenuous the security situation has become in recent days.

“Heavy shelling and other exchanges in our Abu Salim neighborhood this morning,” she wrote last Sunday. Using an Arabic term that means “thanks to God,” she added: “Alhamdullila all safe.”

Later in the week, she sought to dispel a rumor suggesting that the United States was flying armed drones over Libya. “We are not engaged in this fighting, just trying to stay safe under fire,” she wrote.

The U.S.-dominated NATO military campaign that enabled rebels to oust longtime Libyan leader Moammar Gaddafi in the summer of 2011 was initially hailed as a foreign policy victory for the Obama administration. As the country has descended into chaos, and Islamist militant groups have taken root in the east, Libya has become among the most complex challenges in the region for Washington and its allies.

Officials said the United States remains committed to helping Libya.

“We will continue to engage all Libyans and the international community to seek a peaceful resolution to the current conflict and to advance Libya’s democratic transition,” Harf said. “We reiterate that Libyans must immediately cease hostilities and begin negotiations to resolve their grievances.”

Gearan reported from Paris.