At least 20 pickup trucks loaded with antiaircraft guns blocked the roads while men armed with AK-47s and sniper rifles directed traffic away from the building in Tripoli, witnesses said.
Armed groups also tried unsuccessfully to storm the Ministry of Interior and the state news agency, the prime minister said.
“These attacks will never get us down and we will not surrender,” the prime minister, Ali Zeidan, told a news conference. “Those who think the government is frustrated are wrong. We are very strong and determined.”
Tension between the government and armed militias has been rising in recent weeks since a campaign began to dislodge the groups from their strongholds in the capital.
Since Gaddafi was toppled by Western-backed rebels in 2011, Libya has been awash with weapons and roving armed bands that are increasingly attacking state and foreign institutions. Last week, a car bomb destroyed about half of the French Embassy, in the worst attack against a Western country since the killing of the American ambassador, J. Christopher Stevens, in an attack on the United States mission in Benghazi last September.
The show of force on Sunday was to demand that a law 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.
Some officials employed in the Foreign Ministry had worked for the regime.
Libya’s legislature, the General National Congress, had been prevented from voting on the bill in March, when protesters barricaded assembly members inside a building for several hours and demanded they adopt the law.