Twenty-one other people were wounded in the attack, authorities said.
A car bomb exploded near the ministry, prompting security forces to rush to the scene, said special forces spokesman Tarak al-Dawass.
|A firetruck and security officers at the scene of an attack on the Libyan foreign ministry in Tripoli on December 25, 2018. (AFP)|
A suicide bomber then blew himself up on the second floor of the building while a second attacker died when a 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.
IS claimed the attack in a statement distributed on social media, saying that it was carried out by three "soldiers of the caliphate" who were armed with suicide belts and automatic weapons.
Interior Minister Fathi Bash Agha admitted during a news conference that "security chaos" reigned in Libya and was "out of our control".
He said this was creating a "fertile ground" for IS to operate in the North African country.
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 vying 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 Sirte 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.
Bach Agha said he found "zero weapons and zero vehicles" in the ministry's warehouses when he took up his job in October.
"Weakness and a security breakdown" allowed assailants to attack the foreign ministry, he said.
The foreign minister said the UN should lift an arms embargo it has imposed on Libya 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 reporters.
- 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, Britain's ambassador to Libya, also denounced an "appalling terrorist attack" and tweeted his condolences to the families of the victims.
Italian Foreign Minister Enzo Moavero Milanesi joined the chorus of condemnation in a statement reiterating Rome's "solidarity with the Libyan people and their just aspiration to real security".
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. (AFP)