BENGHAZI, Libya/ANKARA (Reuters) - Forces loyal to Libya’s internationally recognized government said on Monday they shelled a Turkish ship off the Libyan coast after it was warned not to approach, and one crew member was killed in what Turkey described as a “contemptible attack”.

Libya is in a state of violent factional chaos with two rival governments backed by various armed groups vying for control of the oil-producing North African state including its ports, four years after rebels overthrew Muammar Gaddafi.

The dry cargo ship was targeted about 10 miles from the coast on Sunday after it was told not to break a ban on approaching the eastern city of Derna, Libyan military spokesman Mohamed Hejazi told Reuters.

The forces of Libya’s internationally recognized government have said they will hit any ships approaching Derna to stop supplies getting to Islamist militants based there.

The Turkish foreign ministry said the vessel was shelled as it approached the nearby Mediterranean port of Tobruk and then attacked from the air as it tried to leave the area.

“We condemn strongly this contemptible attack which targeted a civilian ship in international waters and curse those who carried it out,” the ministry said in a statement, adding that Ankara had protested to the authorities in Libya.

The third officer on the Cook Islands-chartered Tuna-1 vessel died and other crew members were wounded in the attacks, according to the Turkish statement.

It did not specify the assailants, but said the vessel was carrying plasterboard from Spain to Tobruk and was 21 km (13 miles) from its destination when it came under fire.

Hejazi confirmed that one crew member was killed and said one other person was wounded.

A Libyan military source said the vessel was on fire and being towed to Tobruk terminal. But a Turkish foreign ministry official denied this, saying it was returning to Turkey.

“Turkey approached the United Nations and the IMO (International Maritime Organization) in connection with the matter. A note was given to Libya’s Ankara embassy and Istanbul consulate seeking an explanation,” the Turkish official said.

Libya’s rival administration, whose armed supporters took over the capital last summer, condemned the Turkish vessel shelling in a statement as an act of “terrorism” by Gen. Khalifa Haftar, a former Gaddafi ally who leads the military forces of the recognized government.

Internationally recognized Prime Minister Abdullah al-Thinni said in February his government would stop dealing with Turkey because it was sending weapons to a rival group in Tripoli so that “the Libyan people kill each other”.

Turkey denies taking sides in the conflict, saying it supports U.N.-led efforts to broker a peace.

A Libyan warplane from forces loyal to Thinni’s government bombed a Greek-operated oil tanker anchored off Libya’s coast in January, killing two crewmen, amid hostilities between factions vying for power.

Attacks on foreign ships in waters near Libya may complicate European Union efforts to stop traffickers sending thousands of migrants to Europe in often unseaworthy vessels.

Thousands have drowned in the voyage and several EU nations have sent naval vessels to the region to try to stem the migrant influx. But Libyan officials have warned against any measure perceived as an attack on the country’s sovereignty.