African migrants march from Holot detention centre to the Saharonim Prison, an Israeli detention facility for African asylum seekers, on February 22, 2018, to protest at Israel's policy of prison or deportation for migrants (AFP Photo/)

Jerusalem (AFP) - Israel on Sunday freed 207 African migrants from prison following a supreme court ruling after Prime Minister Benjamin Netanyahu controversially reversed a deal with the UN refugee agency on the detainees' fate.

After an operation lasting several hours a spokeswoman for the immigration authority told AFP late on Sunday that all detainees had been released.

There are around 42,000 African migrants in Israel. Authorities transferred 207 of them from a nearby open detention facility in February after they refused to leave the country.

Israel's supreme court on April 10 gave the government until Sunday to finalise a deal it said it was working on to deport some of the migrants to another country.

Without a deal, the court said authorities must release those held at Saharonim prison.

"In light of the fact that the negotiations between Israel and a third country are still ongoing and due to a supreme court ruling, the migrants held in Saharonim prison will be freed today," the immigration authority said in a statement earlier Sunday.

Uganda said on Friday it was "positively considering" a proposal from Israel to accept 500 of the mostly Eritrean and Sudanese migrants.

Earlier this month, Netanyahu cancelled an agreement with the United Nations refugee agency, UNHCR, aimed at avoiding forced deportations of thousands of migrants.

The reversal, just hours after he announced the deal himself in a televised address, followed pressure from his right-wing base.

That left the government with its initial plan, announced in January, under which migrants who entered Israel illegally would face a choice between leaving voluntarily or facing indefinite imprisonment with eventual forced expulsion.

As the migrants could face danger or imprisonment if returned to their homelands, Israel had offered to relocate them to an unnamed African country -- either Rwanda or Uganda, according to deportees and aid workers.

Rwanda has since said it could not be part of the arrangement.

Story continues

The UN refugee agency has strongly criticised the deportation plan and urged Israel to return to the deal, which would have allowed thousands of migrants to remain in the country in return for an equal number being relocated to Western nations.

Some Israelis, including Holocaust survivors who say the country has a special duty to protect migrants, have also opposed the deportation plan.

Of the 42,000 African migrants in Israel, half are children, women or men with families who are not facing immediate deportation, according to interior ministry figures.

Migrants began entering Israel through what was then a porous Egyptian border in 2007. The border has since been strengthened, all but ending illegal crossings.