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.

U.S. District Judge Edward Chen in San Francisco said there's evidence that President Donald Trump’s decision to end temporary protected status for those from Sudan, Nicaragua, Haiti and El Salvador was motivated by racial discrimination against “non-white, non-European aliens.”

TRUMP ADMINISTRATION ENDS TPS FOR EL SALVADOR IMMIGRANTS: WHAT ARE THESE TEMPORARY PROTECTIONS?

As evidence, Chen cited Trump's past comments including his characterization of Mexican immigrants as drug dealers and rapists while on the campaign trail and his allegedly referring to African nations as “s----hole countries” during a White House meeting in January.

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.

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

Chen 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. He said discontinuing TPS would cause "irreparable harm and great hardship."

"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.

Chen’s ruling is the latest case of judges the president’s 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. According to plaintiffs in the lawsuit, 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.

Homeland Security officials said they could not comment on ongoing litigation.

It is not the first time Chen has accused the Trump administration of being motivated by racism. At a hearing last month, Chen cited a memo which he said suggested the decision to end TPS was driven by the administration's America First policy.

The Associated Press contributed to this report.