TRIPOLI (Reuters) - Suicide bombers stormed the head offices of Libya’s electoral commission in Tripoli on Wednesday, killing at least 12 people and setting fire to the building in an attack claimed by the Islamic State militant group.

The assailants also opened fire on employees of the High National Election Commission (HNEC) and fought a gun battle with security forces trying to regain control of the site, officials said.

The attack appeared aimed at derailing efforts to organize elections in Libya by the end of this year, part of a U.N.-led attempt to unify and stabilize the country after years of conflict and political division.

Since December the electoral commission has registered nearly one million new voters across Libya, though no date has been set for polls.

Wednesday’s attack was the first of its kind in Tripoli since 2015. Though security across Libya remains volatile, violence in the capital has recently been limited to localized clashes between armed groups.

Immediately after the attack thick black smoke could be seen billowing from the electoral commission’s offices in the Ghout al-Shaal district west of central Tripoli.

“I saw two suicide bombers myself... they were shouting Allahu Akbar (God is greatest),” said commission spokesman Khaled Omar, who fled the offices with other staff as the attack unfolded.

“A suicide bomber blew up himself inside the commission and the others set a part of the building on fire.”

A security official who spoke to witnesses at the scene of the attack said several gunmen had opened fire on guards while the suicide bombers entered the building, and that some may have later escaped.

The site of suicide attack on Libyan electoral commission is seen in Tripoli, Libya, May 2, 2018 in this still picture obtained from social media video. AL NABAA CHANNEL/via REUTERS

Once inside the bombers shot dead employees at close range before detonating explosives, said the official, who asked not to be named.

Islamic State claimed responsibility for the attack in a statement on Amaq, its news agency. Two assailants -- identified as Abu Ayoub and Abu Toufik -- clashed with security forces before entering the building and detonating explosive jackets after running out of ammunition, the jihadist group said.

The health ministry said 12 people had been confirmed killed and seven wounded. Most of the victims were HNEC staff, with at least two security personnel also killed, Interior Minister Abdulsalam Ashour told a press conference.

The fire blackened the commission building, though HNEC head Emad al-Sayah said the electoral database was safe.

“This breach targeted democracy, not just the HNEC,” Sayah told reporters. “The choice and future of Libyans were targeted.”

Libya has been in a state of turmoil since a 2011 civil war resulted in the overthrow of longstanding ruler Muammar Gaddafi by rebel fighters backed by NATO air strikes.

Elections in 2014 were disputed, resulting in rival governments backed by competing military alliances in Tripoli and the east.

Militants linked to Islamic State have carried out suicide bombings across the north of the country, though the group lost most of its fighters in Libya when it was driven out of its stronghold in the central city of Sirte in 2016.

Libyan and Western officials say militants, including fighters loyal to Islamic State and al Qaeda, are now concentrated in remote desert areas, but also have sleeper cells in coastal cities including Tripoli.

On Sunday a joint meeting of the Arab League, European Union, African Union, and United Nations “emphasized the importance of holding parliamentary and presidential elections” in Libya, noting that they were planned by the end of the year.

Some Libyans and foreign officials have questioned the push for new elections, expressing concern about the lack of security as well as legal and logistical challenges.