Libyan security forces have stormed the headquarters of the country’s national oil company in the capital Tripoli shortly after gunmen had taken hostages and set off explosions in the building.

The health ministry said two people were killed and 10 others were injured in the attack.

Health official Malek Merset had said earlier said that there were dozens of injuries caused by the gunfire, smoke inhalation or explosions.

The national oil company building
Damage can clearly be seen on the outside of the damaged national oil company (AP)

At least one explosion rocked the building soon after the gunmen went in, starting a fire that swiftly spread through the lower floors.

Mustafa Sanallah, head of the Libyan National Oil Company, told a Libyan television channel that explosions and an exchange of gunfire between the attackers and the building’s security guards have caused an unspecified number of deaths and injuries.

“The building was heavily damaged due to the fire. Smoke is everywhere,” Mr Sanallah said.

“The gunmen attacked the lower floors with random shooting and explosions. It’s a very violent attack.”

Libyan security forces
Security forces have clashed with gunmen in the building (AP)

There was no word on the fate of the gunmen, described by Libyan officials as “terrorists”, or whether they were still holding hostages.

Earlier, the interior minister of the UN-backed government, Brig Gen Abdul-Salam Ashour, said the attack was carried out by six gunmen and that employees were inside the building when it took place.

The UN mission in Libya condemned the attack, describing it as “cowardly”, and called on Libya to cease their “futile side conflicts” and unite to rid their nation of terrorism.

The attack followed recent fighting in Tripoli between rival armed groups, which left at least 61 people dead. A ceasefire has been in place since last week.

Libya slid into chaos after the 2011 uprising that overthrew dictator Muammar Gaddafi and led to his death. It is now governed by rival authorities in Tripoli and the country’s east.