Then came the weekend.
In a stream of tweets on Sunday, the president said those who wanted to investigate his ties to Russia were “haters and fools,” ridiculed “crooked” Hillary Clinton’s ill-fated effort to reset relations with Russia and fired back at North Korea’s leader, Kim Jong-un, for calling him old, saying that he could call Mr. Kim “short and fat” — but had restrained himself.
That followed a freewheeling session with reporters on Air Force One on Saturday, in which Mr. Trump dismissed the Russia investigation as a Democratic “hit job” and derided as “political hacks” three former chiefs of the nation’s intelligence agencies, all three of which concluded that Russia had meddled in the 2016 presidential election.
It was hard to say what prompted the sudden change in the president’s demeanor, though the first lady, Melania Trump, who often plays a moderating influence on her husband, dropped off the trip in Beijing, after visiting the Great Wall of China and stroking the paw of a panda bear at the Beijing Zoo. Mr. Trump, 71, could also simply be tired.
Pressed again on Sunday about whether he believed President Vladimir V. Putin’s denials that Russia had intervened, Mr. Trump seemed to walk back his earlier comments somewhat. He said he did not dispute the assessment of the intelligence agencies that Moscow had interfered.
“As to whether I believe it or not, I’m with our agencies, especially as currently constituted, with their leadership,” Mr. Trump said at a news conference with Vietnam’s president, Tran Dai Quang. “I believe in our agencies. I’ve worked with them very strongly.”
Still, Mr. Trump’s endorsement was grudging — he noted that the assessment reflected only four agencies, not 17 — and he repeated his assertion that Washington needed to move on from the Russia investigation to cooperate with the Russians on issues from North Korea to Syria.
“What I believe is, we have to get to work,” he said. “It’s now time to get back to healing a world that is shattered and broken.”
In the short run, Mr. Trump’s comments broke with a narrative that the White House had carefully constructed during this 12-day trip — that of a statesman marshaling a worldwide coalition to confront a nuclear North Korea, and a populist leader working to right trade imbalances.
The president’s tweets and comments also complicated life for White House officials, who had been encouraged by his friendly meetings with the leaders of Japan, China and South Korea and by what they characterized as one of the most effective foreign-policy speeches of his presidency, on the need to confront a nuclear North Korea.
Speaking to reporters here in Hanoi on Sunday, the White House chief of staff, John F. Kelly, insisted that he did not pay attention to Mr. Trump’s tweets or allow his staff to be distracted by them.
“They are what they are,” Mr. Kelly said. “But like, you know in preparation for this trip, we did the staff work, got him ready to go and then at each place we brief him up on whatever the next event is and all that. The tweets don’t run my life; good staff work runs it.”
Until Sunday, Mr. Trump had been careful not to make things personal with Mr. Kim. But after his speech in Seoul, in which he cataloged the brutality of the Kim government, North Korea described him as a “lunatic old man” and urged Americans to force him out of office or face an “abyss of doom.”
That prompted an indignant response from Mr. Trump, who seemed more offended by the gibe about his age than about his mental condition. Shortly before leaving his hotel to meet the Vietnamese president, he tweeted, “Why would Kim Jong-un insult me by calling me ‘old’ when I would NEVER call him ‘short and fat?’ Oh well, I try so hard to be his friend.”
Once at the Presidential Palace, however, Mr. Trump seemed to have gotten over it. Asked whether he could see himself becoming friends with Mr. Kim, he said: “Strange things happen in life. That might be a strange thing to happen, but it’s certainly a possibility.”
“If that did happen,” he continued, “it would be a good thing for — I can tell you — for North Korea. But it would also be good for lots of other places, and it would be good for the world.”