WASHINGTON — President Donald Trump's frustration over rising numbers of undocumented immigrants crossing into the U.S. is stoking tensions among his advisers as some White House officials push for a more aggressive policy that includes completely sealing the southern border, said four people familiar with the discussions.

The differences escalated into an angry, profanity-laced exchange on Thursday between White House Chief of Staff John Kelly and national security adviser John Bolton as a Honduran migrant caravan of roughly 4,000 people approached the U.S. border. The dispute was so heated, according to several people, that Kelly ended up storming out of the White House shortly afterward.

Trump’s hard-line stance on immigration, including family separation policies that involved holding children in cages, has been a centerpiece of his presidency and a core message ahead of the midterm elections. But his failure to secure funding for a promised wall along the border with Mexico, coupled with a renewed surge in border crossings, has tested his ability to make good on his promises.

During a meeting Thursday about the issue, Homeland Security Secretary Kirstjen Nielsen was explaining an 80 percent rise in immigrant families crossing the border when Bolton interrupted her to criticize her handling of the issue, two people familiar with the meeting said.

Bolton said that Nielsen, a close Kelly ally, was doing a poor job with the border and that her department was not producing the needed results, these people said. He argued that she was failing at one of her signature tasks as Homeland Security secretary, they said.

Bolton, as well as Trump's senior policy adviser Stephen Miller, also proposed sending armed guards to the border and denying entry to anyone without proper documentation, including asylum-seekers, according to three people familiar with the discussions.

What began as a policy discussion turned into a harsh exchange between Kelly and Bolton, just steps from the Oval Office, with Kelly telling Bolton that he lacked an understanding of the complexities of immigration policy, and Bolton telling Kelly that his efforts so far have been ineffective, people familiar with the discussion said. The exchange between Bolton and Kelly was first reported by Bloomberg.

According to three people familiar with the exchange, Kelly repeatedly used the f-word to punctuate his points. These people said Kelly, who had served as Trump’s first secretary of Homeland Security, fiercely defended Nielsen, who has come under fire from Trump over her handling of the border.

The advisers then went into the Oval Office to discuss the matter with the president. Kelly ultimately stormed out of the White House early with no resolution on the issue, these people said.

"I’m f---ing out of here," Kelly said, according to one person briefed on the exchange.

A White House official said Bolton and Nielsen spoke in the national security adviser’s office after the Oval Office meeting with Trump to smooth things over. "Both ultimately agreed the goal is to secure the border," the official said, adding that these types of "disagreements can happen."

This disagreement, however, underscores broader tensions between Bolton and Kelly that have simmered since Trump named Bolton his national security adviser in the spring. Kelly opposed the Bolton pick, but was overruled by Trump.

People familiar with their relationship have said Kelly increasingly resents that Bolton reports directly to the president and circumvents his authority as chief of staff. Kelly also sees himself as more of an authority on immigration issues than Bolton, these people have said, and he is fiercely protective of Nielsen.

Nielsen served as Kelly’s deputy chief of staff before Kelly helped make her Trump’s pick to succeed him at the Department of Homeland Security.

Both Kelly and Bolton appear to be jockeying to spearhead a solution that appeals to Trump, whose growing frustration has made the border issue once again a top priority. But one person familiar with their argument said Kelly’s anger largely stemmed from Bolton’s targeting of Nielsen.

While part of their disagreement unfolded near and inside the Oval Office, people familiar with it said, Trump told reporters Thursday that he "had not heard about" it.

White House press secretary Sarah Sanders played down the tensions in a statement Thursday. "While we are passionate about solving the issue of illegal immigration, we are not angry at one another," Sanders said.

Although less prevalent in previous administrations, heated arguments, personality clashes and conflicts have beset the Trump White House from its earliest days. His son-in-law, Jared Kushner, got into an angry White House fight with former Secretary of State Rex Tillerson; Anthony Scaramucci was ousted as communications director after just 10 days following a profanity-laced diatribe that was recorded by a reporter, and the president himself is known for having a volcanic temper, particularly when faced with bad news.

Trump expressed his support Thursday for ordering the military to the southern border and completely closing it, particularly if Mexico does not stop the caravan from Honduras.

"As you know, I am willing to send the military to defend our southern border if necessary," Trump told supporters Thursday night at a rally in Montana. Trump also said the caravan would be a major issue in next month's midterm elections.

Some migrants have turned back to Honduras, but nearly 4,000 were still making their way north and have begun to cross into Mexico.

An internal report compiled by U.S. authorities and obtained by NBC News shows that a small number of Hondurans from the caravan began crossing into Mexico on Thursday night. An additional 2,000 to 3,000 are expected to congregate at the Guatemala-Mexico border on Friday in an attempt to cross northward. More than 1,000 others crossed into El Salvador over the past two days and are now making their way to Guatemala.

One senior administration official said Trump is so frustrated with lack of progress on border security — one of his signature 2016 campaign promises — that he "is absolutely prepared to use any option, including the 'nuclear option' of trying to seal the border."

"He’s dead serious," the official said, which on Thursday caught the president's Cabinet officials and senior advisers "off guard in a big way."

For now, two officials said, Trump is unlikely to enforce a new border policy before the Nov. 6 midterm elections. If the Honduran migrant caravan passes through Mexico, they are expected to arrive at the U.S. border at that time, potentially triggering a strong response from the Trump administration.

Proponents of sealing the border believe a court ruling in favor of the administration on the final version of Trump’s travel ban, which allowed the U.S. discretion in issuing visas, would support blocking entry to the majority of asylum-seekers. Others argue that international law requires the United States to give asylum-seekers due process.

In the meantime, Mexico announced it’s enlisting the help of the United Nations High Commissioner for Refugees to assist with people traveling through Mexico to reach the U.S. border — a step some White House officials are skeptical will work.