“He is a Marine first and foremost,” Mr. Panetta said. “In addition to being a Marine, he was born and raised in Boston” among blue-collar families with traditional views about God and country. “You combine those two and you realize” that he “shares some of these deep values, some of which Trump himself has tried to talk about.”
As tall and commanding in a suit as he was in a uniform, Mr. Kelly has become a central figure in Mr. Trump’s orbit. After six months in the cabinet as secretary of homeland security, Mr. Kelly took over a turbulent and tribal White House last summer and by most accounts imposed more order on the building and staff, if not the Twitter-obsessed president himself.
Mr. Kelly’s focus on improving information flow and decision making in the West Wing gave the impression of a good soldier mainly concerned with process. But that obscured a player who expresses his own sharp views in selected areas, most notably immigration, where he shares Mr. Trump’s commitment to toughening the border and deporting many in the country illegally. His views were forged in part by his time heading the United States Southern Command, which oversees American military operations and security in Central and South America and in the Caribbean.
Mr. Kelly not only expressed willingness to curb refugees coming into the country — in the end, Mr. Trump lowered the cap to 45,000 — he embraced Mr. Trump’s various attempts to close the border to visitors from a group of predominantly Muslim countries. He aggressively turned up the heat on internal immigration enforcement, stepping up deportation of undocumented immigrants, even those without serious criminal records, reversing an Obama administration policy.
Under Mr. Kelly’s leadership, the Department of Homeland Security also went after undocumented parents who bring their children into the country. He directed immigration officials to lodge smuggling charges against the parents, saying they were putting children in danger.
“Kelly has been an enabler of Trump’s mission,” said Juliette Kayyem, a former assistant homeland security secretary under Mr. Obama. “Judge him that way.”
His image as a steady, nonideological figure trying to restore order in the White House in the face of a radical president, she added, was not true. Mr. Kelly, she said, was not “the savior or the hostage.”
Other Democrats have expressed alarm at Mr. Kelly’s views on immigration. At a dinner including Mr. Trump and the Democratic leaders Senator Chuck Schumer of New York and Representative Nancy Pelosi of California, Mr. Kelly gave an extended critique of Mexico, calling it a third-world country in danger of collapsing the way Venezuela has and arguing that the United States needed to guard itself against that, according to people informed about the conversation.
But Senator Tom Cotton, Republican of Arkansas, who recommended Mr. Kelly to Mr. Trump last winter, said the retired general’s background gave him an understanding of the dangers and drawbacks of unfettered immigration. “He knows a lot of the challenges that we face south of the border,” Mr. Cotton said, adding that the issue is “something that he’s lived on a firsthand basis for years.”
Like Mr. Panetta, he pointed to Mr. Kelly’s upbringing.
“I think he appreciates the struggles of America’s working class — the blue-collar workers over the last 30, 40 years, the kind of people who have to take a shower after they get off work, not before they go to work — and the impact that mass unskilled and low-skilled immigration has had on working-class wages in our society,” Mr. Cotton said.
As a cabinet officer, Mr. Kelly frequently lashed out at critics. In March, during a meeting with members of Arab and Muslim communities in Dearborn, Mich., Mr. Kelly threatened to walk out after being posed hard questions about the travel ban and what participants saw as the targeting of Muslim Americans at ports of entry, according to people in attendance.
During a speech in April, Mr. Kelly rebuked members of Congress who complained about what they called overly aggressive immigration enforcement.
“If lawmakers do not like the laws they’ve passed and we are charged to enforce, then they should have the courage and skill to change the laws,” Mr. Kelly said defiantly. “Otherwise, they should shut up and support the men and women on the front lines.”
That drew a rebuke from Representative Henry Cuellar, Democrat of Texas. “I don’t think it’s correct for you to tell members of Congress to shut up,” he said.
Mr. Kelly has also engaged in testy public debates with Senator Kamala Harris, Democrat of California. During a June meeting, Ms. Harris and Mr. Kelly engaged in a contentious back-and-forth as she questioned him about Trump administration threats to cut off funding for so-called sanctuary cities that refuse to cooperate with federal immigration officials.
All of that foreshadowed his attack last week on Representative Frederica S. Wilson, Democrat of Florida, who publicly accused Mr. Trump of insensitivity when he called the widow of Sgt. La David T. Johnson, who was killed this month in Niger. Mr. Kelly called her an “empty barrel” and told an unflattering story about her that was proved untrue by videotape of the event he mentioned.
Mr. Kelly decided himself to head out to the White House briefing room to defend the president, colleagues said, and most of his remarks reflected on his own experience as the father of a slain soldier and the nature of military service. He brought tears to the eyes of other White House aides, who afterward traded emails expressing admiration for Mr. Kelly’s passionate defense of Mr. Trump. It was only afterward that they began to see how the attack on Ms. Wilson came to overshadow the emotion of the first part of his speech.
Mr. Kelly was surprised by the criticism of his speech, colleagues said, but he has not apologized to Ms. Wilson for making false statements about her. White House officials said they opted against it to avoid extending the story.
Mr. Panetta said Mr. Kelly’s attack on a congresswoman reflected his lack of experience in high-level politics. “He knows where the land mines are in the Marines, but he doesn’t know where the land mines are in politics,” Mr. Panetta said. “And he’ll make mistakes as a result, and he certainly made mistakes last week in going after people in that news conference.”
But, he said, it was authentic: “As somebody who worked with this guy, a lot of what he got up to say is a reflection of who John Kelly is.”