A U.S. federal judge barred the Trump administration on Monday from refusing asylum to immigrants who cross the southern border illegally.

U.S. District Judge Jon S. Tigar issued a temporary restraining order after hearing arguments in San Francisco. The request was made by the American Civil Liberties Union and the Centre for Constitutional Rights, which quickly sued after U.S. President Donald Trump issued the ban this month in response to the caravans of migrants that have started to arrive at the U.S.-Mexico border.

In his ruling, Tigar said Congress clearly mandated that immigrants can apply for asylum regardless of how they entered the country. The judge called the latest rules an "extreme departure" from prior practice.

"Whatever the scope of the president's authority, he may not rewrite the immigration laws to impose a condition that Congress has expressly forbidden," Tigar wrote.

'This was an Obama judge'

Trump lashed out at the judge and court when asked about the ruling Tuesday.

"This was an Obama judge," he told reporters outside the White House. "It's a disgrace when every case gets filed in the ninth circuit. Every case in the ninth circuit, we get beaten and then we end up having to go to the Supreme Court like the travel ban and we won."

He vowed to put in "a major complaint."

Tigar was nominated to the court in 2013 by President Barack Obama.

Previous Trump immigration policies, including measures targeting sanctuary cities, have also been blocked by the courts.

A migrant, part of a caravan of thousands from Central America trying to reach the United States, climbs the border fence between Mexico and the United States. (Hannah McKay/Reuters)

Trump issued a proclamation on Nov. 9 that said anyone who crossed the southern border would be ineligible for asylum. The regulations, which will remain in place for three months absent a court order, could potentially make it harder for thousands of people who enter the U.S. to avoid deportation.

"Individuals are entitled to asylum if they cross between ports of entry," said Baher Azmy, a lawyer for the Centre for Constitutional Rights. "It couldn't be clearer."

Migrants arriving in Tijuana

In recent years, tens of thousands of immigrants each year have shown up in the Arizona desert or on the north bank of the Rio Grande in Texas, surrendered to immigration agents and requested asylum. The Department of Homeland Security estimates around 70,000 people a year claim asylum between official ports of entry.

Trump has argued that the recent caravans are a threat to national security.

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.

Demonstrators clash during a protest against migrants from Central America in Tijuana yesterday. (Hannah McKay/Reuters)

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 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 like 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.