Islamic State militants on Monday launched an attack on the port of al-Sidra, Libya's largest oil terminal, military officials said.
Clashes between guards at the terminal and the jihadists led to the death of two guards and 10 of the attackers, Ali al-Hassi, spokesman for Libya's Petroleum Guards Force, said.
A military official loyal to Libya's internationally recognized government, based in Tobruk in the far east of the country, said the air force had intervened and rebuffed the attack.
Islamic State, which is based mainly in Syria and Iraq, controls an area of Libya's Mediterranean coast centred around the towns of Sirte and al-Nofaliyeh, west of al-Sidra.
Its growing presence has lent urgency to international efforts to broker a peace deal between the Tobruk government and a rival, Islamist-leaning administration which controls the capital Tripoli.
Libyan politicians in December signed a UN-brokered agreement to set up a national unity government, but influential figures in both Tobruk and Tripoli are holding out against the deal.