HOUSTON — A federal judge barred the Trump administration from refusing asylum to immigrants who cross the southern border illegally.

President Donald Trump issued a proclamation on Nov. 9 that said anyone who crossed the southern border between official ports of entry would be ineligible for asylum. As the first of several caravans of migrants have started arriving at the U.S.-Mexico border, Trump said an asylum ban was necessary to stop what he’s attacked as a national security threat.

READ MORE: Judge approves settlement giving some migrant parents second chance at asylum

But in his ruling Monday, U.S. District Judge Jon Tigar agreed with legal groups that immediately sued, arguing that U.S. immigration law clearly allows someone to seek asylum even if they enter the country between official ports of entry.

“Whatever the scope of the President’s authority, he may not rewrite the immigration laws to impose a condition that Congress has expressly forbidden,” said Tigar, a nominee of former President Barack Obama.

The Department of Homeland Security did not immediately comment on the ruling, which will remain in effect for one month barring an appeal. In issuing the ban, Trump used the same powers he used last year to impose a travel ban that was ultimately upheld by the Supreme Court.

If enforced, the ban would potentially make it harder for thousands of people to avoid deportation. DHS estimates around 70,000 people a year claim asylum between official ports of entry. But Tigar’s ruling notes that federal law says someone may seek asylum if they have arrived in the United States, “whether or not at a designated port of arrival.”

“Individuals are entitled to asylum if they cross between ports of entry,” said Baher Azmy, a lawyer for the Center for Constitutional Rights, which sued the government alongside the American Civil Liberties Union. “It couldn’t be clearer.”

“Whatever the scope of the President’s authority, he may not rewrite the immigration laws to impose a condition that Congress has expressly forbidden.”

Around 3,000 people from the first of the caravans have arrived in Tijuana, Mexico, across the border from San Diego, California. U.S. Customs and Border Protection said Monday that it closed off northbound traffic for several hours at the San Ysidro crossing. It has also installed movable, wire-topped barriers, apparently to stop a potential mass rush of people.

As of Monday, 107 people detained between official crossings have sought asylum since Trump’s order went into effect, according to DHS, which oversees Customs and Border Protection. Officials didn’t say whether those people’s cases were still progressing through other, more difficult avenues left to them after the proclamation.

DHS has said it wants asylum seekers at the southern border to appear at an official border crossing. But many border crossings such as San Ysidro already have long wait times. People are often forced to wait in shelters or outdoor camps on the Mexican side, sometimes for weeks.

ACLU lawyer Lee Gelernt said that some people seeking asylum cross between official ports because “they’re in real danger,” either in their countries of origin or in Mexico.

“We don’t condone people entering between ports of entry, but Congress has made the decision that if they do, they still need to be allowed to apply for asylum,” he said.

Associated Press journalists Jill Colvin and Colleen Long in Washington contributed to this report.