The slain soldiers had been tasked with guarding the plant in western Sirte, a military official told The Anadolu Agency.
"No one targets troops in Sirte except for the Ansar al-Sharia jihadist group," the official said.
For over two months, military forces loyal to the internationally-recognized House of Representatives have been engaged in confrontations with Islamist militias in several Libyan cities.
Earlier this year, former army chief Khalifa Haftar declared war on militias based in eastern Libya, vowing to "purge" the country of "extremists."
Clashes have raged between the two camps since mid-October, with the House of Representatives declaring its support for Haftar's operation against the militias.
In the three years since the ouster and death of strongman Muammar Gaddafi, rival militias have often locked horns, frequently bringing violence to Libya's main cities, including capital Tripoli and the eastern city of Benghazi.
The sharp divisions have yielded two rival seats of government in the country, each of which has its own institutions.
Two assemblies currently vie for legislative authority: the House of Representatives, which convenes in Tobruk, and the General National Congress, which – even though its mandate ended in August – continues to convene in capital Tripoli.
The two parliaments support two different governments respectively headquartered in the two cities.