Justin Sullivan via Getty Images Protesters hold signs during a demonstration outside of the San Francisco office of the Immigration and Cutsoms Enforcement in June.

SAN FRANCISCO (AP) — A judge on Wednesday blocked the Trump administration from ending protections that allowed immigrants from four countries to live and work legally in the United States, saying the move would cause “irreparable harm and great hardship.”

U.S. District Judge Edward Chen in San Francisco granted a request for a preliminary injunction against the administration’s decision to discontinue temporary protected status for people from Sudan, Nicaragua, Haiti and El Salvador.

The judge said there is evidence that “President Trump harbors an animus against non-white, non-European aliens which influenced his ... decision to end the TPS designation.”

The ruling cited Trump’s 2015 campaign speech in which he characterized 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.

It’s the latest case in which judges have cited Trump’s own comments to rule against his immigration policies. His words have been turned against him in lawsuits over decisions to separate families at the border, end legal protections for young immigrants and ban people from some Muslim-majority countries.

Temporary protected status is granted to countries ravaged by natural disasters or war and lets citizens of those countries remain in the U.S. until the situation improves back home. About 300,000 people have received those protections.

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,” Chen wrote.

Many have children who were born in the U.S. 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.

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. We will continue to fight for the integrity of our immigration laws and our national security,” O’Malley’s statement said.

Attorneys 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,” said Crista Ramos, 14, whose Salvadoran mother was in the program. “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 mom.”

Chen questioned the administration’s motives at a hearing last month. He cited a memo that he said suggested the decision was driven by the administration’s America First policy.

He asked an attorney for the U.S. Justice Department to respond to plaintiffs’ allegations that America First meant excluding immigrants who are not white.

Adam Kirschner, a government attorney, said the memo showed then-Homeland Security Acting Secretary Elaine Duke grappling with what to do about temporary protected status. Kirschner said input from the White House was expected on an issue like this, but the final decision was Duke’s.

Chen repeated Trump’s vulgar comment about African countries while responding that any influence the White House had on Duke could be relevant to the claims that the administration’s moves were discriminatory.

Chen ruled Wednesday that evidence shows Duke’s decision “may have been done in order to implement and justify a pre-ordained result desired by the White House.”

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 that the program would expire for El Salvador in September 2019.

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

The Trump administration ended the program for the other three countries as well.

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.

___

Jablon reported from Los Angeles.