A KENYAN court has ruled that the government must not close the world’s largest refugee camp and send more than 200,000 people back to war-torn Somalia.

The decision eases pressure on Somalis who feared the camp would close by the end of May.

Kenya’s internal security minister abused his power by ordering the closure of Dadaab camp, Judge John Mativo said, adding that the minister and other officials had “acted in excess and in abuse of their power, in violation of the rule of law and in contravention of their oaths of office”.

Rights groups Amnesty International, Kituo cha Sheria and the Kenyan National Commission on Human Rights had challenged the government’s order to close the camp.

Kenya’s government quickly said it will appeal against the ruling.

The judge called the order discriminatory, saying it goes against the Kenyan constitution as well as international treaties that protect refugees against being returned to a conflict zone.

President Uhuru Kenyatta’s government has not proved Somalia is safe for the refugees to return, the judge said, also calling the orders to shut down the government’s refugee department “null and void”.

Somalia remains under threat of attacks from homegrown extremist group al-Shabab.

Some Kenyan officials have argued that the sprawling refugee camp near the border with Somalia has been used as a recruiting ground for al-Shabab and a base for launching attacks inside Kenya.

But Kenyan officials have not provided conclusive proof of that.

US President Donald Trump’s temporary ban on travel from seven majority-Muslim countries, including Somalia, had put added pressure on the Dadaab refugees.

Last weekend, about 140 of the Somali refugees who had been on the brink of resettling in the United States were sent back to Dadaab instead.

Said Abuka, a community leader in Nairobi and a refugee for 22 years, said the court ruling would help the Somali refugees.

Newborn babies could not be registered as refugees because of the shutdown of Kenya’s refugee department, he said.

“After months of anxiety because of the camp closure deadline hanging over their heads, increasingly restricted asylum options and the recent US administration suspension of refugee resettlement, the court’s judgment offers Somali refugees a hope that they may still have a choice other than returning to insecure and drought-ridden Somalia,” said Laetitia Bader, Africa researcher at Human Rights Watch.

Amnesty International welcomed the ruling, saying it affirmed Kenya’s legal obligation to protect people who seek safety from harm and persecution.

“Today is a historic day for more than a quarter of a million refugees who were at risk of being forcefully returned to Somalia, where they would have been at serious risk of human rights abuses,” the rights group’s Muthoni Wanyeki said in a statement.

Territory control map of Somalia, also showing Dadaab refugee camp in Kenya Somalia’s UN-backed government, with the help of a 22,000-strong African Union force, is battling Islamist group al-Shabab to regain control of the country.

But it has only managed to secure major towns.

The militants, who impose a strict version of Islam in the areas they control, still mount bombings and have carried out a series of attacks in neighbouring Kenya.

Al-Shabab has carried out several attacks on Kenya, which sent troops to Somalia in 2011 to fight the militants. The attacks include the September 2013 attack on the Westgate mall that killed 67 people and the 2015 attack on Garissa University that killed 148 people, mostly students.

Kenya is currently building a fence along its 700km (435-mile) border with Somalia, but has completed only 4km so far.