A United States judge has blocked the Trump administration from ending protections that have allowed 300,000 immigrants from four countries to live and work legally in the United States, saying the move would cause "irreparable harm and great hardship".

Key points: US plans would affect immigrants from Sudan, Nicaragua, Haiti and El Salvador

US plans would affect immigrants from Sudan, Nicaragua, Haiti and El Salvador Judge cites Trump's rhetoric against Mexican people and African countries

Judge cites Trump's rhetoric against Mexican people and African countries The Justice Department slams the ruling, saying it "usurps the role of the executive branch"

US District Judge Edward Chen in San Francisco granted a request for a preliminary injunction against the administration's decision to end temporary protected status, or TPS, for people from Sudan, Nicaragua, Haiti and El Salvador.

The judge said there was evidence "President Trump harbours an animus against non-white, non-European aliens which influenced his ... decision to end the TPS designation".

The ruling cited Mr Trump's 2015 campaign speech in which he characterised Mexican immigrants as drug dealers and rapists, his call to bar Muslims from entering the United States and his vulgar reference to African countries during a meeting about immigration at the White House in January.

The TPS designation offers protection from deportation to immigrants already in the United States, including those who entered illegally, from countries affected by natural disasters, civil conflicts and other problems.

The ruling said the Government failed to show the harm of continuing the 20-year-old program, and that the plaintiffs established how uprooting those immigrants could hurt the local and national economy.

"Beneficiaries who have lived, worked, and raised families in the United States (many for more than a decade) will be subject to removal," Judge Chen wrote.

Many have children who were born in the US and may be faced with the choice of "bringing their children with them (and tearing them away from the only country and community they have known) or splitting their families apart", the ruling said.

The lawsuit from immigrants who have received the protections alleges the administration's decision was motivated by racism.

Decision condemned by Justice Department

US President Donald Trump signs an executive order at the White House in Washington last year. ( Reuters: Kevin Lamarque )

Justice Department spokesman Devin O'Malley said the ruling "usurps the role of the executive branch".

"The Justice Department completely rejects the notion that the White House or the Department of Homeland Security did anything improper," he said in a statement.

"We will continue to fight for the integrity of our immigration laws and our national security."

Lawyers for the plaintiffs praised the ruling and issued statements from some of those involved.

"I was so happy when I found out about the judge's decision," Crista Ramos, 14, whose Salvadoran mother was in the program, said.

"Ever since the TPS terminations were announced, I have been wondering how I can live a normal life if I am about to lose my mum."

El Salvador was designated for the program in 2001 after an earthquake, and the country's status was repeatedly renewed.

The Trump administration announced in January El Salvador's inclusion in the program would expire in September 2019.

The administration concluded El Salvador had received significant international aid to recover from the earthquake, and homes, schools and hospitals there had been rebuilt.

Immigrants from Haiti covered by the TPS will lose their protected status in July 2019, Nicaraguan immigrants in January 2019 and Sudanese immigrants in November 2019.

More than 200,000 immigrants could face deportation because of the change, and they have more than 200,000 American children who risk being uprooted from their communities and schools, according to plaintiffs in the lawsuit.

AP/Reuters