One man was killed and four people wounded as Libyan security forces repelled armed demonstrators who attacked government headquarters in Tripoli, a senior official said.
The country's interim prime minister Abdel Rahim al-Kib read out a statement on television denouncing the violence and vowing not to give way to "outlaws" making demands at the end of a gun.
The casualties occurred as government forces sought to clear the area and open access to the besieged building, interim government spokesman Nasser al-Manaa said.
Manaa was speaking to journalists inside the government complex just hours after the attack.
The one man killed and three of those wounded were members of the interior ministry's Tripoli High Security Committee called in to deal with the situation after dialogue failed, he said.
One of the assailants was also wounded.
Tripoli High Security Committee head Khaled Besher said 14 assailants had been arrested.
A group of demonstrators had shown up at 9:00 am (0700 GMT), he told journalists. Armed men had soon joined their ranks.
By noon, the crowd had grown to 200 people, including gunmen from the western town of Yefren backed by about 50 trucks mounted with anti-aircraft guns and rocket launchers.
Representatives aired their grievances including the non-payment of cash stipends for former rebels who fought against the regime of Moamer Kadhafi, Manaa told reporters.
After some gunmen forced their way into the building and opened fire, the interim government started evacuating personnel and called for back-up, he added.
Earlier, a public official said former rebels had opened fire with anti-aircraft cannon.
"Some men entered the premises and fired from inside," sparking chaos as people scrambled for cover, he said.
Residents in the area reported hearing heavy exchanges of gunfire.
By 5:30 pm, fresh security forces were posted at the back, front and side entrances of the glass government building, which had dozens of its windows shattered in the attack.
Ammunition shells littered the area and the capital's usual sunset traffic jams were cleared by the violence, an AFP journalist said.
The Libyan government started paying out stipends to former rebel fighters a few months ago, but suspended the process after a few weeks citing irregularities, provoking angry protests from unpaid fighters.
Kib appeared on television late Tuesday to denounce the violence and to pay tribute to the member of the interior ministry security force who had been killed.
The government "will not give in to blackmail and to outlaws and will not negotiate under the threat of arms," he said.
"The interior ministry has arrested the attackers and the situation is completely under control," he added.
He called on Libyans to turn out to pay their respects to Ali al-Gaout, the security force member killed in the clash, describing him as a hero and a martyr.
It is not uncommon for demonstrators to carry arms when staging rallies in front of government buildings in the capital.
But Manaa, who blamed the violence on the dark legacy of 42 years of dictatorship, said: "We don't want this to become a widespread phenomenon."
In a message to former rebels, he stressed that there was no need to make "demands through force" and proposed dialogue instead.
Tuesday's violence marks the worst attack in Tripoli against Libya's new rulers, who have struggled to rein in rogue militias.
But the tough reaction shows the interim authorities are willing to call on their growing forces to counter threats against state institutions.
The clashes came as Libyans across the country registered to vote in the first national poll in more than four decades. Libyans are expected to vote for a constituent assembly in June.