WASHINGTON – The Trump administration's struggles to curtail illegal immigration have exposed a deep rift among the president and his top advisers, one that could lead to changes in the Cabinet and undermine the government's response to a record surge of migrant families at the southern border.

Even as President Trump continues to believe immigration will be a political winner next month in helping turn out his conservative base for the midterm elections, tensions in the West Wing have reached a boiling point. A profane shouting match over immigration this week among top aides prompted Chief of Staff John Kelly to storm out of the White House and marked the culmination of weeks of mounting anxiety, several senior administration officials said.

Trump's own escalating frustration has led him to excoriate aides for not taking more aggressive actions and to offer his own ideas, officials said. He has ruminated this week over the possibility of sending more soldiers to the border, even though thousands of National Guard troops have been deployed there since April with no evidence of a deterrent effect.

In the summer, the president was so upset by the border numbers that he proposed sealing the entire 1,954-mile U.S.-Mexico border, including shuttering legal ports of entry, blocking trade flows and halting tourism and travel, according to the senior administration officials, who spoke on the condition of anonymity to discuss sensitive internal deliberations.

"Close the whole thing!" Trump demanded at one point during an Oval Office meeting, the officials said. He was talked out of it by advisers who highlighted the effect such a measure would have on more than $600 billion in U.S.-Mexico annual trade, as well as the potential damage to bilateral relations, according to the officials.

The worsening immigration numbers are particularly fraught for Trump, who centered much of his 2016 campaign around incendiary vows to build a border wall – which has not been built – and has begun focusing on immigrants as a dire threat in the final weeks before the Nov. 6 midterms.

Experts said the White House is straining under the same political dilemma that past administrations encountered in trying to manage the massive U.S. immigration system despite Congress's inability to strike a comprehensive legislative reform package. Trump is hitting the limits of what he is legally able to do through executive authority, they said, and the United States has relatively few tools to deal with the gang violence, poverty and hunger propelling a mass exodus of Central American migrant families over the past five years.

"The tension between the White House and the Department of Homeland Security reminds me of when people tried to characterize stopping illegal immigration as a willingness problem – and accused the Obama administration of not wanting to stop it," said John Sandweg, who served as a high-ranking DHS official under President Barack Obama. "This administration is learning the hard way – it's not a lack of willingness. It's just our ability [as a government] to do so that is limited."

White House officials have sought to play down the tensions. After news broke Thursday about the squabble just outside the Oval Office between Kelly and national security adviser John Bolton over the performance of Homeland Security Secretary Kirstjen Nielsen, press secretary Sarah Sanders issued a statement saying Bolton and Nielsen had patched things up.

But Kelly was audibly cursing as he left the White House grounds and he did not return that day, according to people with knowledge of the situation.

The blowup came after Nielsen, during a White House meeting, had touted an effort by the Mexican government to enlist help from the U.N. Refugee Agency to process asylum claims from a caravan of thousands of Honduran migrants traveling north toward the United States. Trump has demanded that the Mexican government disband the group and threatened to cut off foreign aid or upend a new trade deal if it fails to do so.

Nielsen characterized the United Nation's involvement as a significant measure that could help stem the flow, according to administration officials. Bolton, a longtime critic of the United Nations, responded that the international body was ineffective and expressed disbelief at Nielsen's view, the officials said, prompting an argument over the DHS chief's performance.

Kelly, who served as the head of that agency for the first six months of Trump's tenure and handpicked Nielsen to replace him, jumped in to defend her.

"The White House wants to see more passion, energy and a more proactive approach, rather than waiting for the president to get pissed off and then come up with a solution," one senior DHS official familiar with the dispute said of Nielsen.

Trump backed Bolton and another influential senior White House aide, Stephen Miller, who also has been critical of Nielsen. The conflict has reverberated through DHS amid speculation that Nielsen is among the Cabinet members most at risk of losing her job after the midterms.

Kelly has defended Nielsen repeatedly, drawing eyerolls from other staff members. At senior staff meetings, he has often praised Nielsen even though her name had not come up, according to two people who have attended the meetings.

"It was counterproductive for her," one of these people said. "Kelly's overprotection of her actually hurt her."

A former colleague of Nielsen's said there would be no immediate replacement if she departs, noting that the deputy DHS secretary role has been vacant since Elaine Duke's departure in February.

"I'm sure she's exhausted, but I think she would like to stay a little bit longer, at least to serve for a year," the person said, noting that Nielsen has been in the role for only 10 months.

The internal strife threatens to make an already challenging situation even more arduous. In 2014, the Obama administration faced a humanitarian crisis at the border when tens of thousands of unaccompanied minors and families with children overwhelmed patrol stations. The situation prompted a broad emergency response from the federal government that included Congress approving new resources, including additional money to house the children, and a $750 million aid package to Guatemala, El Salvador and Honduras – the Northern Triangle nations where most of the migrants were coming from.

The numbers of families and children this year have surpassed the 2014 totals. Trump has responded by threatening to cut off foreign aid to those nations, a move experts said would only exacerbate the problems.

Amy Pope, who as deputy homeland security adviser under Obama helped coordinate the 2014 response, said that crisis sparked some disagreements among agencies, including DHS, the State Department and Health and Human Services – though she did not recall any shouting matches.

"Trump threatening to curtail all foreign assistance to Honduras is actually counterproductive," Pope said. "All evidence shows a couple dominant reasons why people leave – violence and a lack of economic opportunity and no judicial accountability. It's what foreign assistance is meant to address."

At campaign rallies and on Twitter, Trump has sought to blame Democrats and foreign leaders for the mounting number of families at the border. In private, he has summoned Nielsen to the West Wing for regular meetings, aides said.

Trump is pushing for a more muscular response, and he favors sending more U.S. soldiers to the border. About 1,600 National Guard troops are deployed in four states after Trump ordered the move in the spring, according to Homeland Security officials.

But DHS officials say they need more legal and legislative firepower. The vast majority of Central American migrants who reach the border are turning themselves in to Border Patrol agents, claiming a fear of return and a desire to seek asylum. More National Guard troops and the border wall that Trump has proposed would be largely irrelevant, experts have said.

By Friday afternoon, video clips showed the Honduran migrants, having made their way through Guatemala, attempting to cross into Mexico, some wading through a river.

Back in Washington, one senior DHS official put the scene into perspective.

"We see the equivalent of a caravan cross our border every day," the official said. "We're catching 1,500 people a day."