HANOI, Vietnam — For the last week on the road, President Trump had been measured, disciplined and studiously scripted as he picked his way through the geopolitical minefields of Asia.

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.