WASHINGTON — When thousands of migrant children ended up stranded in U.S. Border Patrol stations last spring, President Donald Trump’s administration characterized the crisis as a spontaneous result of the record crush of migrants overwhelming the U.S. immigration system.

But the backup also was a result of policy decisions that officials knew would ensnare unaccompanied minors in bureaucratic tangles and leave them in squalid conditions, according to dozens of interviews and internal documents viewed by The Washington Post.

The policies, which administration officials began pursuing soon after Trump took office in January 2017, made it harder for adult relatives of unaccompanied minors to secure the children’s release from U.S. custody. Enhanced vetting of sponsors — including fingerprints and other paperwork — and the sharing of that information between child welfare and immigration authorities slowed down the release of children and exposed the sponsors to deportation.

The government knew the moves would strain child shelters, according to documents and current and former officials, but it was aimed at sending a message to Central American migrants: Coming to the United States illegally has consequences.

Administration officials said the policy was designed to protect children from potential abusers or criminals, but they also wanted to create a broad deterrent effect; they reasoned that undocumented migrants might hesitate to claim their children for fear of being deported. Authorities weighed deterrence — a central aspect of U.S. immigration policy under both President Barack Obama and Trump — against the possibility of children crowding into border stations. And they chose to push forward, knowing what would result.

“This will strain bed capacity,” authorities wrote in a discussion paper in February 2018.

The approach caused thousands of unaccompanied minors to be stranded in U.S. custody and exacerbated the appearance of a crisis on the southern border — a major element underlying the administration’s public request for billions of dollars in additional funding from Congress.

Lawyers were allowed to visit children in the border stations, and Democratic lawmakers were invited to tour the facilities when they were at their worst. They witnessed — and shared with the public — scenes of desperate children held in crowded cells without basic necessities.

According to current and former government officials, and emails and memos detailing the Trump administration’s strategy, it is clear they knew that without enough beds in government shelters, children would languish in Border Patrol stations not equipped to care for them, making the government a target of lawsuits and public criticism — both of which occurred.

Top DHS officials have warned that the reprieve from the record influx of migrants in recent months is probably temporary. Acting Customs and Border Protection commissioner Mark Morgan said last month that the number of people crossing the border is still higher than at the same time last year and remains a “crisis.” Migration also typically increases in the spring, and the U.S. government is preparing for another surge of families and unaccompanied minors.

Such a potential wave of children is what inspired the early discussions about policy changes within the Trump administration in 2017 — along with debate about the policy’s effects.

Staff at the Department of Health and Human Services’ Office of Refugee Resettlement, which is in charge of caring for unaccompanied migrant children, argued against the policy in weekly memos during the summer of 2017. Jonathan White, then deputy director of the ORR’s children’s program, warned in a July 2017 memo that the administration’s plan to separate children from their families and to alter the process of handing children over to sponsors would “result in significant increases” in how long children would be held.

White wrote that children would spend an average of 95 days in federal custody, far longer than the 20 days federal law allows, and that the department would need at least 6,500 additional beds in just three months. White declined to comment for this story.

Documents reviewed by The Post show that officials also estimated that HHS would need an additional $686 million in funding — more than 50 percent above its planned budget — to accommodate the policy and create additional bed space.

But the administration did not formally request extra money for that purpose at the time, according to senior Democratic and Republican congressional aides who spoke on the condition of anonymity to discuss private negotiations.

Mark Weber, an HHS spokesman, did not dispute those details but maintained that the border backups resulted from a historic influx of unaccompanied children. In May alone, 9,000 children were referred to the government’s care, he said.

Administration officials also thought the backlog would be short-lived.

“At some point in FY19, the deterrent effect of the new policy should stop families and unscrupulous adult aliens from using the reunification process, normalizing and reversing the volume trend” of unaccompanied minors arriving at the border, authorities wrote in a discussion paper that the National Security Council shared with senior administration officials. The paper was shared with an interagency group that met regularly in the White House Situation Room to discuss immigration and border security.

Some senior officials acknowledged in interviews that they expected some children to remain in custody for longer periods of time, but they said the policy was developed with child safety in mind; they did not want children to be released to smugglers or criminals.

“My number one concern on this was making sure that kids were safe,” Tom Homan, former acting director of U.S. Immigration and Customs Enforcement, said in an interview. “I know it’s a tough decision. It was never easy. You have to weigh the operational concerns, and the humanitarian concerns, and how long they’re going to stay in detention. ... Yeah, it was going to increase the bed stay, but it wouldn’t be like twofold, threefold, fourfold. We thought it was worth a try, and it if doesn’t work, we can always pedal back and change gears.”

Acting ICE director Matthew Albence said the policy was part of the “deterrent effect” the government was seeking: “The goal was to prevent these children from coming on this dangerous journey.”

Albence, Homan and other Trump administration officials say the backlog arose because of Washington politics, blaming Democrats in Congress for being too slow to authorize funding for more shelter beds at facilities designed to care for children.

“No one who values child welfare and safety would argue smuggled, exploited and unaccompanied children at the southern border should be handed over to illegal alien ‘sponsors’ without reliable identity confirmation and background checks,” said deputy White House press secretary Hogan Gidley. “The only ones responsible for crowded shelters are Democrats who want to preserve and expand loopholes used by child smugglers for purely political purposes.”

A few months after the policy was implemented, HHS officials determined that it was not improving child safety.

Advocates saw a darker motive in policies that they say were “intentionally developed to inflict maximum anguish on children,” said Heidi Altman, of the National Immigrant Justice Center. She said officials knew that their plans “would trigger a chain of events that left children hungry, abused and sick in overcrowded CBP facilities.”

The Department of Homeland Security did a test run of the policy in the summer of 2017, instructing border agents to interview young migrants about the relatives they wanted to live with in the United States. They then created “target folders” for those adults that could be used to take action against them, according to internal emails that the American Immigration Council obtained via the Freedom of Information Act and made available online.

At the ORR, then-director Scott Lloyd was thinking about the administration’s “moral imperative” to protect children from smugglers and to ensure that gangs were not exploiting the child shelter system to enter the country.

“Our legal responsibilities are child welfare,” Lloyd said in an interview. “But even from a child welfare perspective, it’s desirable to deter people from taking that risk, putting their kids in that type of harm.”

Lloyd said he and his staff agreed that better communication between his agency and DHS was the best way to address those concerns.

“We needed to know if a kid had any gang ties or gang ties in their family — we needed to make sure that DHS had that information and that we had that information,” Lloyd said.

The partnership was formalized in an agreement that mandated significantly stricter fingerprinting and screening requirements for all adults who hoped to sponsor a migrant child or who lived in a house where a migrant child might stay.

“If this could get finalized and implemented soon, it would have a tremendous deterrent effect,” Gene Hamilton, counsel to then-attorney general Jeff Sessions, wrote in notes he sent by email in December 2017 to Chad Wolf, the senior DHS official who is now in line to take over as acting secretary. The existence of the notes — but not the identity of the authors or the recipients — was first reported by NBC News.

Wolf declined to comment.

HHS Secretary Alex Azar and then-DHS secretary Kirstjen Nielsen — the two department heads tasked with carrying out the policy — voiced serious concerns, according to two officials familiar with the discussions. They worried that the agreement would be impossible to implement, could lead to longer detention times for children and would be viewed publicly as unnecessarily harsh, said the officials, who spoke on the condition of anonymity to discuss internal policy deliberations.

Caitlin Oakley, an HHS spokeswoman, did not dispute that account, but she said in a statement that Azar “supports the Trump administration’s goal of enforcing immigration laws and securing the border.”

Nielsen declined to comment.

One HHS employee who spoke on the condition of anonymity to discuss internal matters recalled Lloyd telling staffers that the White House wanted them “to do everything you can to prevent backups into border stations. But it is better that there be a backup in a border station than that we not enforce immigration laws and that we not deter migration.”

Lloyd denied that account.

“I don’t ever recall holding, even temporarily, the idea that backups at border stations was a remotely acceptable scenario,” Lloyd said.

Internal memos show that for months before implementing the policy, government lawyers worried about lawsuits and discussed ways to claim that the policy would make children safer. In a January 2018 draft memo, viewed by The Post, Justice Department lawyers proposed defending the plan to conduct enhanced background checks and share them with enforcement agents as a means of protecting migrant children from witnessing the eventual deportation of their parents or relatives.

“We can argue that whether a proposed sponsor is subject to removal is a key factor in determining suitability, given the impact that immigration enforcement against, or detention of, a sponsor would have on the circumstances faced by” unaccompanied minors living with the sponsor, Justice Department lawyers wrote in January 2018 correspondence with DHS and HHS officials as part of an “analysis of litigation risk” associated with the agreement.

By the fall of 2018, most of the families had been reunited, and the number of unaccompanied children crossing the border had fallen, but the population of children in the shelters continued to grow, according to HHS data. By October 2018, migrant children were spending an average of more than 90 days in federal custody — exactly as White had predicted — more than twice the length of stays two years earlier.

Kevin Dinnin, the head of the nonprofit that operated a shelter for migrant children in Tornillo, Texas, said the crush of minors became increasingly severe through late 2018. Images of teenagers behind chain-link fences shuffling single-file from tent to tent had drawn public outrage, and Dinnin could not understand why children continued arriving at the shelter even though crossings had slowed and family separations ended.

“The problem was, kids were coming and not being discharged,” Dinnin said. “The average length of stay just kept increasing.”

An HHS official who spoke on the condition of anonymity to discuss sensitive policy decisions said the agency would never have opened the Tornillo shelter had it not been for the agreement with DHS.

“It was the increase in average length of care that created a need for thousands of beds,” the official said.