The Trump administration must turn over documents explaining its decisions to deport more than 200,000 people who were admitted to the United States after catastrophes in their home countries, a federal judge in San Francisco ruled Thursday.

Advocates for former residents of El Salvador, Nicaragua, Haiti and Sudan are challenging the administration’s decision to revoke their temporary protected status. That status, under a 1990 federal law, allows people fleeing disasters in their homeland to live and work in the U.S. under permits that are renewed every 18 months.

President Trump’s Department of Homeland Security said it withdrew the protections because the hardships caused by the disasters — earthquakes in El Salvador and Haiti, a hurricane in Nicaragua and a civil war in Sudan — have ended. But the lawsuit contends the real reason was racism.

When Trump reportedly referred to Haiti and African nations as “s—hole countries,” it was during a White House meeting on temporary protected status in January. A week later, the administration announced the termination of protected status for Haitians. Deportations to the four countries are scheduled from November 2018 to September 2019.

In addition, advocates argued, the Trump administration failed to state a reason for abruptly changing previous administrations’ policies. Those had allowed people to retain protected status based on new hardships in their former homelands, like outbreaks of disease and violence. Federal law requires the government to provide a “reasoned explanation” for changing policies or practices that affect the rights of private citizens.

U.S. District Judge Edward Chen refused to dismiss the suit in June, saying the advocates had plausibly alleged that Trump’s statements showed racial bias that could have influenced his administration’s decision. On Thursday, Chen ordered the administration to give the plaintiffs internal documents about conditions in the four countries, the decisions to revoke protections and strategies for explaining them to the public.

Trump administration lawyers argued that documents about internal government deliberations are confidential and need not be disclosed. Chen, who reviewed 20 of the documents in his chambers, said some involved internal deliberations, but still must be turned over because they concern serious issues and “the federal interest in the enforcement of federal law.”

If the administration says other specific documents are too sensitive to be disclosed, Chen said, it could try to make its case to a federal magistrate Friday.

Chen will hold a hearing, sometime before protected status for Sudan expires in November, to decide whether to block the deportations.

“We should now be able to see these documents that the government has tried to keep secret,” said a lawyer for the plaintiffs, Jessica Karp Bansal of the National Day Laborer Organizing Network. “We’ve introduced a lot of evidence that the terminations were motivated by discrimination. We think these documents will further support our claims.”

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko