The Department of Homeland Security announced a new policy Thursday banning asylum seekers from entering the USA and requiring them to stay in Mexico, a change that upends the way migrants fleeing persecution have been welcomed into the country for decades.

Under U.S. law, people requesting asylum at the southern border – either at a port of entry or after illegally entering the country, and who pass an initial screening – are allowed to stay in the country pending an immigration judge’s decision on their application.

Under the policy unveiled Wednesday by Homeland Security Secretary Kirstjen Nielsen, that will no longer be the case. Anybody who requests asylum will be processed by federal immigration agents, then immediately returned to Mexico.

For weeks, the U.S. and Mexican governments negotiated over a similar policy dubbed “Remain in Mexico,” but the Trump administration was unable to reach an agreement with the administration of new Mexican President Andres Manuel Lopez Obrador, who took office Dec. 1.

Instead, the United States implemented the policy unilaterally, Nielsen said before the House Judiciary Committee on Thursday. The Mexican Foreign Ministry said Thursday it will grant migrants with pending asylum applications in the USA a humanitarian visa to remain in Mexico, work permits and the ability to travel back and forth to the USA for court hearings.

The Mexican government is struggling to accommodate thousands of members of a migrant caravan who are camped out in Tijuana, awaiting their chance to apply for asylum. A Mexican official said Thursday that the new U.S. policy will add to that burden.

"This unilateral measure puts (migrants) in a situation of enormous vulnerability," said Alejandro Alday, legal adviser to the Foreign Ministry.

Nielsen defended the move as necessary to secure the U.S. border while allowing legitimate asylum seekers a better chance to win entry.

“Let me be clear: We will undertake these steps consistent with all domestic and international legal obligations, including our humanitarian commitments,” Nielsen told the committee. “All affected migrants will receive humanitarian visas to stay on Mexican soil, they will be given the ability to apply for work and other protections while they await a legal U.S. determination.”

The DHS relies on authorities granted under a section of the Immigration and Nationality Act that allows an attorney general to order the return of asylum seekers arriving at a land port to the country they attempted to enter from. But the law states that the attorney general can remove only migrants who are "not clearly and beyond a doubt entitled to be admitted."

A separate part of the Immigration and Nationality Act allows asylum seekers entry if they simply show they have a “credible fear” of returning to their home country.

“This plan cannot be done lawfully,” said American Civil Liberties Union attorney Lee Gelernt, who led a lawsuit that forced the administration this summer to reunify families separated at the southern border with Mexico.

A senior Homeland Security official said the new policy goes into effect immediately but will be rolled out at ports of entry along the southern border. The official, who spoke on condition of anonymity to fully explain the policy, said the goal is for asylum seekers to stay in Mexico and be allowed to enter the USA only for necessary court hearings related to their application.

Nielsen said the policy is needed to stem a flood of unaccompanied minors and family units arriving at the USA to request asylum, knowing they will probably be granted entry while their case slowly winds through the backlogged immigration court system. In the past two months, more than half of the 102,000 people caught illegally crossing the southern border were minors or family units.

Before the DHS announcement, Rep. Jerrold Nadler, D-N.Y., who will become Judiciary Committee chairman in January when Democrats retake control of the House, warned Nielsen that her department would face intense scrutiny over its treatment of families, minors, asylum seekers and all others along the southern border.

He likened the administration’s "zero-tolerance" policy that led to thousands of family separations this summer to “mass kidnapping by the federal government.” He described policies attempting to limit asylum as dangerous, haphazard and chaotic. He said Nielsen should prepare for investigations into all those matters.

"I want to put you and the department on notice: The time for accountability has arrived," Nadler said. "The Trump administration, including DHS under your watch, has launched a relentless attack against immigrants of all stripes. The time for zero accountability is over."

Nielsen received praise from committee Republicans for the new policy. Rep. Steve Chabot, R-Ohio, thanked her for bringing “some sanity” back to the U.S. immigration system.

Rep. Zoe Lofgren, D-Calif., told Nielsen the policy will surely be met with lawsuits similar to those that struck down two other attempts to limit asylum.

“You’ll be … in court, as you know … your policy does not adhere to the requirements of the immigration law," she said.

Contributing: David Agren in Mexico City.