The attack on the offices of the country's election commission happened as the commission was registering voters ahead of elections to be held later this year.

Several people are also reported to be injured in the attack.
Several people are also reported to be injured in the attack. (AA)

Daesh suicide bombers attacked Libya's election commission in the capital on Wednesday, killing at least 12 people in the worst such attack in years that aimed to disrupt a nation-wide vote planned for later this year.

The two bombers infiltrated the building in central Tripoli and fired on people inside, then detonated their explosives when their ammunition ran out, Daesh said in a statement circulated by its affiliated Amaq news agency. 

The Health Ministry earlier said the attack also set fire to the building, which could be seen in online videos showing thick black smoke billowing upward and security forces engaging in a gun battle.

Daesh and other militants in Libya oppose democratic elections, which the United Nations and Libya's foreign backers are urging to take place this year despite security problems in the oil-rich North African country. 

Militants have often targeted elections in other countries, and Daesh has called for attacks on voting infrastructure in Libya.

Four armed assailants attacked the building on Wednesday morning, a senior security official in Tripoli, Mohamad al Damja, said.

"They killed the guards before opening fire at people on the premises," he said.

At least two of the attackers detonated their explosives when the security forces arrived, Damja added, describing the building as seriously damaged after it caught on fire.

Election hopes

The United Nations mission in Libya condemned the "terrorist attack" 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 UN is hoping that Libya can hold elections this year as it seeks to leave behind years of chaos since the 2011 ouster of dictator Muammar Gaddafi.

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.

Elections were banned during Gaddafi's 42-year rule, and after his ousting legislative polls were organised in 2012 and 2014.

But turmoil has continued in Libya with rival militias, tribes and militants 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 6 million.

While most recent attacks across Libya 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, Daesh claimed an attack on Tripoli's luxury Corinthia Hotel that killed nine people, including five foreigners.

Source: TRTWorld and agencies