LONDON — President Trump arrived in London Monday evening planning to tout a foreign policy accomplishment his presidential campaign wants him to run on: successfully pressuring allies to pay more toward the costs of running NATO.

Less than 48 hours later — after he was put on the defensive in front of the cameras and then was the subject of gossip at a private reception of world leaders, a moment caught in a viral video — Mr. Trump canceled a planned news conference before heading back to Washington earlier than planned.

[Politicians have a long history of being caught saying impolitic things. Let’s roll the tape.]

The timing was not perfect. Mr. Trump had hoped the 70th anniversary celebration of NATO might provide a flattering stage and a triumphant narrative, even as Democrats on Capitol Hill on Wednesday trotted out sober legal scholars to testify at the House Judiciary Committee’s first public impeachment hearing.

But instead of creating a split screen, Mr. Trump failed to produce the statesmanlike narrative his campaign had hoped for. The result was he appeared boxed in both at home and abroad, ultimately overshadowed by diplomatic dynamics that put him on his back foot.