Suicide attackers stormed the Libyan foreign ministry in the capital Tripoli on Tuesday, killing at least three people including a senior civil servant, the authorities said.
Twenty-one other people were wounded in what authorities said was a suicide attack carried out by "terrorists".
A car bomb exploded near the ministry, prompting security forces to rush to the scene, said special forces spokesman Tarak al-Dawass, accusing the Islamic State jihadist group (IS) of responsibility.
A suicide bomber then blew himself up on the second floor of the building while a second attacker died when the suitcase he was carrying exploded, he said.
A third assailant, who was unarmed and wearing a bulletproof vest, was killed by security forces outside, Dawass added.
At least three people were killed and 21 wounded, according to the health ministry.
Foreign Minister Tahar Siala said one of the dead was senior diplomat Ibrahim al-Shaibi who headed a department in his ministry.
Plumes of smoke were seen rising from the building as ambulances, paramedics and security forces gathered outside.
There was no immediate claim of responsibility.
Interior Minister Fathi Bash Agha admitted during a news conference that "security chaos" reigned in Libya and was "out of our control".
As a result, he said, the situation was creating a "fertile ground" for IS to operate in the North African country, although he did not blame the jihadists for the "terrorist" attack.
Torn apart by power struggles and undermined by chronic insecurity, Libya has become a haven for jihadists since the ouster and killing of Moamer Kadhafi in 2011.
– Jihadist foothold –
Two competing administrations, rival militias, tribes and jihadists have been competing for control of territory and the country\’s vast oil wealth.
IS took advantage of the chaos to gain a foothold in the coastal city of Sirte in 2015.
Forces loyal to the UN-backed Government of National Accord (GNA) regained control of the city in December 2016 after eight months of deadly fighting.
Since then, some jihadists have returned to the desert in an attempt to regroup and reorganise.
The interior minister said his department lacked the equipment necessary to restore law and order in Libya.
He said that when he took up his job in October he found "zero weapons and zero vehicles" in the ministry\’s warehouses.
"Weakness and a security breakdown" allowed Tuesday\’s attackers to storm the foreign ministry and carry out their attack, Bach Agha said.
The foreign minister called on the UN to lift an arms embargo on Libya that has been put in place since the 2011 uprising.
"Stability cannot be restored… without a partial lifting of the embargo. It is needed to guarantee security and combat terrorism," Siala told the news conference.
– Envoys denounce attack –
The head of the UN mission in Libya (UNSMIL) denounced the "cowardly terrorist attack" in a statement.
Ghassan Salame also pledged to work with Libyan people "to prevent terrorist groups from turning Libya into a haven… for their crimes".
Frank Baker, the British ambassador to Libya, also denounced an "appalling terrorist attack" and tweeted his condolences to the families of the victims.
In September, IS claimed responsibility for a suicide attack on the headquarters of Libya\’s National Oil Company in the heart of Tripoli which left two dead and 10 wounded.
Four months earlier, it claimed an attack on the electoral commission\’s headquarters which left 14 dead.
In April, the GNA launched an operation to track down IS fighters operating in areas of western Libya under its control.
Last month IS claimed responsibility for an attack on militia forces in southeastern Libya in which at least nine people were killed.
The US military has regularly carried out strikes on jihadists in Libya, particularly south of Sirte.
The GNA was set up under a 2015 UN-brokered deal, but a rival administration based in the country\’s east aligned with military strongman Khalifa Haftar refuses to recognise its authority.
Rival Libyan leaders had agreed to a Paris-brokered deal in May to hold a nationwide election by the end of the year.
But instability, territorial disputes and divisions have delayed plans for elections.