Administration officials signaled that they would continue to defend the policy as it moved through the courts.

“Our asylum system is broken, and it is being abused by tens of thousands of meritless claims every year,” Katie Waldman, spokeswoman for the Department of Homeland Security, and Steve Stafford, the Justice Department spokesman, said in a statement.

They said the president has broad authority to stop the entry of migrants into the country. “It is absurd that a set of advocacy groups can be found to have standing to sue to stop the entire federal government from acting so that illegal aliens can receive a government benefit to which they are not entitled,” they said. “We look forward to continuing to defend the executive branch’s legitimate and well-reasoned exercise of its authority to address the crisis at our southern border.”

Presidents indeed have broad discretion on immigration matters. But the court’s ruling shows that such discretion has limits, said Stephen Yale-Loehr, an immigration scholar at Cornell Law School.

“The ruling is a significant blow to the administration’s efforts to unilaterally change asylum law. Ultimately this may have to go to the Supreme Court for a final ruling,” said Mr. Yale-Loehr.

The advocacy groups accused the government of “violating Congress’s clear command that manner of entry cannot constitute a categorical asylum bar” in their complaint. They also said the administration had violated federal guidelines by not allowing public comment on the rule.

But Trump administration officials defended the regulatory change, arguing that the president was responding to a surge in migrants seeking asylum based on frivolous claims, which ultimately lead their cases to be denied by an immigration judge. The migrants then ignore any orders to leave, and remain unlawfully in the country.