WASHINGTON — The White House chief of staff and the national security adviser got into a profanity-laced argument about immigration outside the Oval Office early Thursday morning, two people briefed on the altercation said, prompting the chief of staff to leave the White House complex and not return for the rest of the day.

The blowup between John F. Kelly, Mr. Trump’s chief of staff, and John R. Bolton, his national security adviser, was loud enough to be overheard by several officials in the West Wing. It erupted as the president — disappointed by new government data showing that his restrictive immigration policies have failed to discourage migrants from seeking entry into the United States — is grasping to resolve a problem that has bedeviled his administration.

A third person described the episode as little more than a typical airing of differences between Mr. Bolton and Mr. Kelly, who has a temper. All three spoke on the condition of anonymity to describe an internal conversation.

The three people said Mr. Kelly and Mr. Bolton were sparring over an issue that has frequently angered the president and has often prompted him to lash out at Kirstjen Nielsen, who succeeded Mr. Kelly as the secretary of homeland security after serving as his deputy chief of staff in the White House. Mr. Bolton was siding with the president, who has angrily blamed Ms. Nielsen for failing to stanch the flow of migrants across the border, while Mr. Kelly, who is fiercely protective of his protégé, defended her, the people said.