“We have some martyrs and people injured,” the official said on condition of anonymity.
Witnesses said shots were heard and black smoke could be seen rising from the headquarters of the national election commission.
Libya’s health ministry published a “provisional toll” of three seriously wounded.
The electoral commission is considered to be one of the few credible and independent institutions in the country, which has been marred by violence since the 2011 ousting of dictator Moamer Kadhafi.
Elections were banned during Kadhafi’s 42-rule and after his ousting legislative polls were organised in 2012 and 2014.
But chaos has continued in Libya with rival militias, tribes and jihadists vying for power.
A 2015 UN-backed deal to set up the unity Government of National Accord (GNA) in Tripoli failed to end the turmoil, as divisions continue with a rival administration in the east.
UN special envoy Ghassan Salame said in February he hoped for parliamentary and presidential elections in Libya by the end of 2018, but warned conditions were not yet ready for polling.
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.