Gunmen surrounded Libya's Foreign Ministry on Sunday, calling for a ban on officials who worked for deposed dictator Muammar Gaddafi holding senior positions in the new administration.
Just days after the French embassy in Tripoli was bombed, the armed protest raised fresh security fears in the capital and the German embassy suspended some of its activities.
At least 20 pick-up trucks loaded with anti-aircraft guns blocked the roads while men armed with AK-47 and sniper rifles directed the traffic away from the Foreign Ministry, witnesses said.
Armed groups also tried unsuccessfully to storm the Ministry of Interior and the state news agency, according to the prime minister who called a news conference to address the problem.
"These attacks will never get us down and we will not surrender," Ali Zaidan told reporters.
"Those who think the government is frustrated are wrong. We are very strong and determined."
Since Gaddafi was toppled by Western-backed rebels in 2011, Libya has been awash with weapons and roving armed bands that are increasingly targeting state institutions.
Tensions between the government and armed militias have been rising in recent weeks since a campaign was launched to dislodge the groups from their strongholds in the capital.
Sunday's protest was to demand a law - which has already been proposed - be passed, banning Gaddafi-era officials from senior government positions. The law could force out several ministers as well as the congress leader, depending on the wording adopted.
"The Ministry of Foreign Affairs will remain closed until the political isolation law is implemented," the commander of the militia told Reuters.
The foreign ministry had been targeted because some officials employed there had worked for Gaddafi, he said.
Libya's legislature, the General National Congress, has previously been prevented from voting on the bill, when protesters barricaded assembly members inside a building for several hours in March demanding they adopt the law.
"The country will remain in crisis so long as these people are present," assembly member Tawfiq Al-Shehabi told Reuters.
The German embassy reduced its activities, a spokesman said, after the prime minister's assertion it had stopped work at its Tripoli mission.
"The German embassy continues to operate but public access is temporarily restricted," the spokesman said, declining to say how long the measures would remain in place.