Islamic State militants have released two Bangladeshi hostages, who were among a group of foreign workers abducted when the rebels attacked a Libyan oilfield, the foreign ministry said.

The hostages were held for more than two weeks after the attack on the Al-Ghani oilfield, south of the Libyan city of Sirte.

Helal Uddin and Mohammed Anowar Hossian were freed on Tuesday evening and stayed in Sirte hospital overnight, according to the Libyan foreign ministry.

The city is around 700km (435 miles) from the Libyan capital of Tripoli.

Libya has been in turmoil since the Nato-backed campaign to overthrow long-time dictator Muammar Gaddafi in 2011. The country currently has two rival governments and is awash with arms.

The chaos has provided fertile conditions for extremist Islamist militant groups to increase their power and carry out attacks.

Libyan militants claiming allegiance to the Islamic State have attacked foreigners in a number of high profile incidents, including an assault at a Tripoli hotel and the execution of a group of Egyptian Christian migrant workers.

Militants this month attacked a number of oilfields in the vicinity of al-Ghani, resulting in companies pulling out staff and shutting down production at 11 fields in the region.

The United Nations is leading negotiations to broker a deal between the rival factions in Libya, amid growing concern regarding the growth of militant Islamism in the North African state.