After weeks of talks, the Mexican government reluctantly agreed to accept the waiting migrants, which could substantially reduce the number of people trying to gain entry into the United States and deter even those with the most credible asylum claims.

Mexican officials did not say where the immigrants would be housed or what resources they would be given, but noted that humanitarian visas and work permits would be made available.

The policy shift amounts to the boldest effort yet by the Trump administration to discourage people from seeking refuge in the United States.

Kirstjen Nielsen, the homeland security secretary, called the move “historic” and said the government was acting under emergency provisions of the Immigration and Nationality Act. The change is effective immediately.

“Today, I am announcing historic measures to bring the situation under control,” Nielsen said in testimony to the House Judiciary Committee, adding that “aliens trying to game the system to get into our country illegally will no longer be able to disappear into the United States.”

She said the administration was taking “lawful unilateral action to stop illegal entry now.”

The policy follows a series of other limits on immigration that the administration has introduced, including separating migrant families, limiting the number of people who can apply for asylum each day, tightening requirements to win a case and restricting the locations where people can apply. (The first policy was reversed in an executive order, and the last has been temporarily blocked by a federal court.)

“It’s a very significant border security development,” Secretary of State Mike Pompeo said in an interview with the Fox News host Laura Ingraham.

Pompeo said the United States had “made clear to the Mexican government” the shift in policy and said Mexico would offer opportunities to “protect the rights of those migrants.”

The administration has said the changes are meant to weed out people who do not qualify for asylum, but migrant rights groups argue that they would also affect those legitimately fleeing for their lives. The new policy was introduced less than a week after two Honduran teenagers were killed in an apparent robbery in Tijuana.

The boys had been staying in shelters that house asylum-seekers preparing to enter the United States.

“Our concern is that this is going to endanger more lives,” said Michelle Brané, the director of migrant rights and justice at the Women’s Refugee Commission. “People who are waiting, and especially children, are really vulnerable.”

As a result of the new curbs, shelters for asylum-seekers in Mexico have been overwhelmed recently by people who would previously have been allowed into the United States on the day they presented themselves at the border, but now have to wait weeks or months.

Brané said she considered the policy “more of an abdication to our responsibility to process people seeking asylum in a fair manner.”

As with many of the administration’s harshest immigration plans that have been introduced with little notice — such as the travel ban and family separations — it was unclear Thursday how exactly the new policy would apply.

The move was seen by immigration advocates as a hard-line deterrent that would force many of the migrants, even those fleeing violence and persecution, to return home. It could also give the United States a rationale to close ports of entry, the advocates said.

“I am surprised the new Mexican government would agree to carry Trump’s water on this, given his harsh rhetoric toward Mexicans,” said Kevin Appleby, the policy director of the Center for Migration Studies. “The administration will use this agreement moving forward to put up a virtual wall against asylum-seekers. In some ways, Mexico will be paying for a wall.”

The new policy will most likely alleviate pressure on U.S. border agents who for months have argued that they are overwhelmed by the record number of migrant families seeking asylum. U.S. Customs and Border Protection houses the families temporarily, usually for several days, while they are processed.

Concerns about the agency’s handling of children peaked this month, when a 7-year-old girl died in Border Patrol custody. The Trump administration did not take responsibility for the death, though days afterward, Kevin K. McAleenan, the commissioner of Customs and Border Protection, told Congress, “Our Border Patrol stations and ports of entry were built to handle mostly male, single adults in custody, not families or children.”

A senior Department of Homeland Security official said that Thursday’s announcement surprised many people in the agency’s leadership, as well as the rank-and-file employees who would be charged with carrying out the policy.

Many logistical concerns had yet to be addressed, the official said, and it was still unclear whether anyone might be exempt — such as children traveling alone.

Critics of the policy predicted that it would soon be challenged in court, on the grounds that it might violate Congress’ intention to allow asylum-seekers into the United States. Additionally, the critics noted, the U.S. should adhere to international conventions that prohibit governments from returning refugees to places where they face a threat to their life or freedom.

Pompeo dismissed the chances of a legal challenge succeeding. “We are confident we are on firm ground,” he said.

Mexican officials said they were told of the U.S. decision on Thursday morning in letters from the Department of Homeland Security and the U.S. chargé d’affaires in Mexico, John S. Creamer. The Mexican Foreign Ministry has essentially agreed to accept the decision by the United States.

A spokesman for the ministry, Roberto Velasco, said the move did not represent an agreement between the two countries, but rather “a unilateral move by the United States that we have to respond to.”

The decision to accept the asylum-seekers is likely to be seen as a capitulation by the Mexican government to President Donald Trump, who said on Twitter two weeks ago that Mexico would house asylum applicants to the United States on its soil.

Given the public enmity between Trump and Mexican leaders, the decision to turn Mexico into a waiting room for migrants seeking entry to the United States is bound to stir anger in Mexico.

Responding to a question from Rep. Robert W. Goodlatte, R-Va., the House Judiciary Committee chairman, Nielsen said that the Trump administration wanted to change the policy of “catch and release” to “catch and remain” by keeping those seeking illegal entry in Mexico.

She said the policy shift was an effort “to discourage those claiming asylum fraudulently.”

“We’ve got to fix the asylum laws,” she said.

This article originally appeared in The New York Times.