WASHINGTON — President Trump was in an especially ornery mood after staff members gently suggested he refrain from injecting politics into day-to-day issues of governing after last month’s raucous rally in Arizona, and he responded by lashing out at the most senior aide in his presence.

It happened to be his new chief of staff, John F. Kelly.

Mr. Kelly, the former Marine general brought in five weeks ago as the successor to Reince Priebus, reacted calmly, but he later told other White House staff members that he had never been spoken to like that during 35 years of serving his country. In the future, he said, he would not abide such treatment, according to three people familiar with the exchange.

While Mr. Kelly has quickly brought some order to a disorganized and demoralized staff, he is fully aware of the president’s volcanic resentment about being managed, according to a dozen people close to Mr. Trump, and has treaded gingerly through the minefield of Mr. Trump’s psyche. But the president has still bridled at what he perceives as being told what to do.

Like every other new sheriff in town Mr. Trump has hired to turn things around at the White House or in his presidential campaign, Mr. Kelly has gradually diminished in his appeal to his restless boss. What is different this time is that Mr. Trump, mired in self-destructive controversies and record-low approval ratings, needs Mr. Kelly more than Mr. Kelly needs him. Unlike many of the men and women eager to work for Mr. Trump over the years, the new chief of staff signed on reluctantly, more out of a sense of duty than a need for affirmation, personal enrichment or fame.