LONDON — He quoted Roosevelt and gently greeted frail veterans at a D-Day commemoration, hours after proclaiming Bette Midler a “psycho” and Chuck Schumer a “creep.” He exalted soldiers’ bravery while dismissing his avoidance of service in Vietnam, calling it a country “nobody heard of.” He toasted Britain’s queen at a Buckingham Palace banquet, after calling London’s mayor a loser.

For President Trump, reconciling his impulses with the expectations for an American president has often posed a hurdle. And when he had idle time during his three-day trip to Britain, the gap between the two — which has come to define his presidency — was jarring.

Mr. Trump’s trip to Britain ended Wednesday much as it had begun: as a split screen of a president embracing regal respectability on one side and settling scores on the other.

His host for the state visit was the royal family. With the exception of encouraging one state dinner guest to say nice things about him on television as Queen Elizabeth II stood nearby, Mr. Trump was well-behaved and well-received, according to British officials who had been concerned about possible missteps.