NEW YORK — A second federal judge has blocked the Department of Homeland Security from forcing tens of thousands of Haitians to return to their native country.

U.S. District Judge William F. Kuntz in New York issued a nationwide injunction Thursday preventing the department from terminating Temporary Protected Status for Haitians.

Kuntz ruled on a lawsuit filed by Haitians in Florida and New York that challenged the Trump administration's decision to end the status granted to Haiti after its 2010 earthquake.

The trial in federal court in Brooklyn stemmed from one of seven lawsuits filed by immigrants and advocates over the 2017 move to end the program. The program has allowed about 300,000 people from Haiti, El Salvador, Nicaragua, Sudan and other countries to stay in the U.S. for years following natural disasters or violence in their home countries.

In October, a California judge hearing another of the lawsuits temporarily blocked the changes covering people from those four countries, forcing the administration to maintain their protected status for now.

But the Brooklyn case, which covered only Haitians, was the first time the administration's move to end the program had been put on trial.

Kuntz said the plaintiffs offered persuasive evidence that the policy change was motivated by "a discriminatory purpose of removing non-white immigrants to the country."

His 145-page ruling cited evidence that officials from Homeland Security and other federal agencies "reverse engineered the TPS review process to achieve the desired political outcome: the termination of Haiti's TPS."

A spokesperson for Homeland Security said in an email the department is "complying with intervening orders" but additional change is needed.

"What is often not reported is that the Trump Administration has forcefully advocated for Congressional action to provide legal status for long-standing TPS beneficiaries in good standing: a change to the law is needed, not judicial intervention," the spokesperson.

The government is expected to appeal the ruling.

In response to the ruling in California, the Justice Department denied the administration had done anything improper and said the ruling "usurps the role of the executive branch."

An attorney for the plaintiffs, Per Sejal Zota of the National Immigration Project of the National Lawyers Guild, said the ruling "vindicates the brave struggle of Haitian TPS holders who challenged Trump, because the law was on their side."