Libyan authorities have released 28 Eritreans and seven Nigerians who were captured and enslaved by Isis in Sirte and had been held in detention since the jihadist group lost the city in December.

The group, all but two of whom are women and children, escaped from Sirte, a former Islamic State stronghold in central Libya, while forces from the nearby city of Misrata battled to oust the militants late last year.

Some of the women were on their way to Europe when Islamic State fighters kidnapped and held them as sex slaves.

After they escaped from Sirte, they were investigated for possible ties to the group and held for several months in a Misrata prison.

Reuters has documented how Islamic State used enslaved refugee women to reward its fighters in Libya. In stories published last year, the women recounted how the group forced them to convert to Islam and sold them as sex slaves.

In November, a Reuters reporter visited some of the captives at a military post in Misrata. Their new captors, the women said then, starved and humiliated them. At least one woman, a 16-year-old, was pregnant and in need of urgent care.

The Libyan attorney-general's office announced that it had cleared the women of any wrongdoing in mid-February, but their release was delayed for several more weeks, with no explanation.

On Wednesday, they were received by staff from the UN refugee agency (UNHCR) and the Libyan Red Crescent, before being taken to a shelter for medical checks.

“I'm very happy, I can't describe how I feel, but I am very happy, I can start a new life and see my family again,” one 14-year-old Eritrean girl told Reuters before leaving the prison with the rest of the group on a Red Crescent bus.

A UNHCR official said the entire group had scabies, but otherwise appeared to be in reasonable physical condition.

The agency expects to resettle the Eritreans as refugees.

“We will send them to a safe house where they can be treated if they need medical treatment, and receive assistance from us, and be protected,” said Samer Haddadin, head of the UNHCR's Libya mission.

“At the same time we will be processing them for refugee status determination... and we are doing this to make sure we can find a resettlement country for those who meet the resettlement criteria.”

The Nigerians, five women and two children, will be able to apply for asylum or be offered repatriation.

In pictures: Isis' weapons factories Show all 11 1 /11 In pictures: Isis' weapons factories In pictures: Isis' weapons factories A mortar round fin manufactured by Isis in Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis rocket components discovered in Gogjali, Mosul, Iraq in November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis mortars discovered near Karamlais, Iraq, in November 2016 CAR In pictures: Isis' weapons factories An Isis rocket launch frame in Qaraqosh, November 2016 Conflict Armament Research In pictures: Isis' weapons factories A memo from Isis' COSQC on quality control at a manufacturing facility in Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Electrically-operated initiators manufactured by Isis in forces Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis mortar tubes at a manufacturing facility in Karamlais, November 2016 Conflict Armament Research In pictures: Isis' weapons factories An Isis mortar production facility discovered in Gogjali, Mosul, in November 2016 Conflict Armament Research In pictures: Isis' weapons factories An Isis weapons manufacturing facilities near Mosul in November 2016 Conflict Armament Research In pictures: Isis' weapons factories Stocks of French-manufactured Sorbitol, Latvian potassium nitrate and Lebanese sugar at an Isis weapons factory in Iraq Conflict Armament Research In pictures: Isis' weapons factories A destroyed Isis weapons facility in Qaraqosh, Iraq, November 2016 Conflict Armament Research

Dozens of women and children who escaped from Sirte or were picked up there by Libyan forces are still being held in Misrata. They include Libyans, Tunisians, and nationals from several sub-Saharan African countries. A group of Filipino nurses were freed in February.

Islamic State took control of Sirte in early 2015, turning the coastal city into its most important base outside Syria and Iraq and stationing hundreds of foreign fighters there. It took Misrata-led forces almost seven months to recapture the city.