Suicide bombers stormed Libya's electoral commission in Tripoli on Wednesday, killing at least a dozen people in an attack claimed by the Islamic State jihadist group.
The bloodshed comes as the international community pushes for elections it hopes will help calm the turmoil that has plagued the North African country since the 2011 ouster of dictator Moamer Kadhafi.
Two armed assailants attacked the electoral commission building, shooting guards and officials before blowing themselves up, Interior Minister Abdelsalam Ashour told a news conference.
The internationally backed Government of National Accord (GNA) denounced "the cowardly suicide attack" and pledged its "commitment to the democratic process".
At least 12 people were killed and seven wounded, according to the health ministry.
Two policemen were among those killed, the interior ministry said.
Eyewitnesses earlier said shots and at least two explosions were heard, while black smoke could be seen rising from the commission headquarters.
The Islamic State group (IS) issued a statement claiming the attack, which it said was in response to a call by its spokesman this month to target polling stations in the Middle East.
The United Nations mission in Libya condemned the assault and said it extended "its condolences to the families of the victims who lost their lives".
"Such terrorist attacks will not deter Libyans from moving forward in the process of consolidating national unity and building the state of law and institutions," it said on Twitter.
The attack came just two days after a quartet formed by the UN, the African Union, the Arab League and the European Union stressed "the importance of holding parliamentary and presidential elections" in Libya.
At the same time it said that "the conduct of such elections requires a conducive political and security environment."
Britain's minister for the Middle East, Alistair Burt, condemned the attack on the electoral commission, which he said "plays an invaluable role in supporting Libya's progress on the democratic path."
The UN is hoping that Libya can hold elections this year as it seeks to leave behind years of chaos since Kadhafi's overthrow.
No date has been set for polls, which are supposed to be preceded by a referendum on a draft constitution and the drafting of an electoral law.
UN special envoy Ghassan Salame said in February he was aiming for parliamentary and presidential elections in the North African country by the end of 2018, but warned conditions were not yet ready for polling.
The electoral commission is considered to be one of the few credible and independent institutions in the country.
Its head Imed al-Sayeh reassured the country after Wednesday's attack that the voter database was " in a safe place".
"The commission is still strong and it is still able to organise any poll," he said.
Elections were banned during Kadhafi's 42-rule and after his ousting legislative polls were organised in 2012 and 2014.
But turmoil has continued in Libya with rival militias, tribes and jihadists vying for territory and the country's vast oil wealth.
A 2015 UN-backed deal to set up the GNA in Tripoli failed to end the turmoil, as divisions continue with a rival administration in the east.
Human Rights Watch warned in March the country was far from ready in political, judicial or security terms for elections, citing harassment of activists and journalists as among the problems to be overcome.
A new constitution has to be put to a referendum and an electoral law adopted before polling.
As of March, 2.4 million Libyan voters had been registered of a population of six million.
Despite the December 2016 loss of its bastion Sirte in northern Libya, IS remains active in parts of Libya.
While most recent attacks have been outside Tripoli, the capital remains mired by insecurity.
In January clashes between rival militias around the city's only working international airport left some 20 people dead.
In 2015, IS claimed an attack on Tripoli's luxury Corinthia Hotel that killed nine people including five foreigners.