A federal judge on Wednesday ordered the Trump administration to temporarily halt its plan to end a special federal immigration program that has allowed hundreds of thousands of immigrants to legally live and work in the U.S. for decades.

U.S. District Judge Edward Chen ruled that the administration may have side-stepped federal rule-making guidelines, imposed undue political pressure on staffers, and violated the Equal Protection Clause by basing its decision "on animus against non-white, non-European immigrants."

The ruling is the latest blow against President Donald Trump's efforts to overhaul the nation's immigration laws, following court orders limiting his travel ban targeting majority Muslim countries, his attempt to end the Deferred Action for Childhood Arrivals program, and his policy of separating migrant families along the southwest border.

The preliminary injunction ordered by Chen prevents the deportation of an estimated 240,000 immigrants from El Salvador, Haiti, Nicaragua and Sudan, who were facing a series of deadlines starting in November to depart the country or risk becoming undocumented immigrants. These immigrants had been granted permission to be in the U.S. under the Temporary Protected Status program, better known as TPS. The humanitarian program was created in 1990 to help immigrants from countries that suffered war or major natural disasters.

The Department of Homeland Security, which manages TPS, has argued that the program has been wrongly extended for years, and that conditions in those four countries are now suitable for thousands of their residents to return home.

More:Trump administration ends special immigration protections for 57,000 Hondurans

Related:Trump administration overruled U.S. embassy officials to end immigration program

But the Northern California federal judge disagreed with the administration and sided — at least for now — with the plaintiffs. He set a hearing for Oct. 26.

In reaching his decision, Chen, who was appointed by President Barack Obama, ruled that there is no immediate harm to the federal government if its decision to end TPS is temporarily halted. But he wrote that there would be enduring, longstanding harm to TPS holders, and the communities in which they live, if they’re forced to leave the country.

Chen cited a brief filed by 17 states that estimated they would lose $132 billion in gross domestic product, $5.2 billion in Social Security and Medicare contributions, and $733 million in employer turnover costs if TPS recipients are sent home.

As for the TPS holders themselves, Chen focused on the thousands of U.S.-born children they've had since living in the U.S.

TPS holders are “faced with a Hobson’s 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 judge wrote.

Edwin Murillo, 42, and his wife, Mily Rivas, 40, who are originally from El Salvador and have two U.S.-born children, faced that very difficult decision. They were undecided about what do but were pretty much opposed to returning to El Salvador, a country they say remains plagued by poverty and violence.

“I prefer hiding from lamigra (immigration authorities) than running from the crime in my country,” said Murillo when reached by telephone at the family’s home in Dallas, Texas. He and his wife each have TPS and have lived in the U.S. for 20 years.

Murillo and his wife took part in a caravan that is traveling across the U.S. for 12 weeks to drum up support for TPS holders. They say their goal is not to further extend TPS, but to convince Congress to pass legislation that would allow TPS holders to legalize their status permanently.

More:Migrant caravan protests Trump phase-out of temporary protected status

Also:Decision on Temporary Protect Status for 60,000 Hondurans coming soon

Chen focused much of his 43-page decision on the way that the Trump administration reached its decision. He wrote that former Homeland Security Acting Secretary Elaine Duke did not appear to have reached her decision to end TPS based on the facts before her, but was “largely carrying out or conforming with a predetermined presidential agenda to end TPS.”

Chen said that agenda may have been tainted by racial bias. The judge listed off multiple comments and actions by Trump, during his presidential campaign and after moving into the White House, as indications that the TPS termination had a racial component behind it.

The judge listed:

- Trump’s comments during his June 2015 speech announcing his candidacy when he characterized Mexicans as drug dealers, criminals and rapists.

- His December 2015 call for a “total and complete shutdown of Muslims entering the United States.”

- A report in the Washington Post in January 2018 that President Trump referred to El Salvador, Haiti and African nations as "shithole countries."

- A February 2018 speech at the Conservative Political Action Conference where Trump “used MS-13…to disparage immigrants, indicating that they are criminals and comparing them to snakes.”

“The issues are at least serious enough to preserve the status quo,” he wrote.

The Justice Department said Chen's decision "usurps the role of the executive branch" and vowed to fight his ruling in court.

"The Court contends that the duly elected President of the United States cannot be involved in matters deciding the safety and security of our nation's citizens or in the enforcement of our immigration laws," Justice spokesman Devin O'Malley said in a statement Wednesday night. "The Justice Department completely rejects the notion that the White House or the Department of Homeland Security did anything improper."

The suit against DHS was filed last March by the American Civil Liberties Union of Southern California and other immigrant advocates.

“Despite the administration’s efforts to twist the existing TPS statute, this preliminary injunction preserves its long-existing intent and avoids the deportation of more than three hundred thousand individuals to countries unfit to accommodate them and, equally importantly, prevents the separation of hundreds of thousands of U.S. citizen children from their parents,” said Sean Commons, an attorney with the Sidley Austin law firm who represented the plaintiffs.

“Judge Chen’s decision reaffirms the importance of our judicial system and the checks and balances in place to hold our government accountable,” he said.

The ruling does not affect the termination of TPS for two other countries: Nepal and Honduras. But attorneys are sure to press other courts to follow suit and temporarily suspend those decisions.

Contributing: Daniel Gonzalez of the Arizona Republic