Donald Trump and Kim Jong Un exchanged warm words as they came together for a historic nuclear summit that seemed unthinkable months ago.
The formal document signing followed a series of meetings at a luxury Singapore resort.
The once-bitter rivals clasped hands in front of a row of alternating US and North Korean flags, then held a one-on-one meeting, additional talks with advisers and a working lunch.
After the signing, Mr Trump said he expected to meet Mr Kim “many times” in the future and, in response to questions, said he “absolutely” would invite the North Korean leader to the White House.
For his part, Mr Kim hailed the “historic meeting” and said they “decided to leave the past behind”.
In a moment that would never happen in North Korea, reporters began yelling questions at the pair after they signed the document.
The meeting was the first between a sitting US president and a North Korean leader.
Aware that the eyes of the world were on a moment many people never expected to see, Mr Kim said many of those watching would think it was a scene from a “science fiction movie”.
After meeting privately and with aides, they moved into lunch at a long flower-bedecked table. As they entered, Mr Trump injected some levity into the day’s extraordinary events, saying: “Getting a good picture everybody? So we look nice and handsome and thin? Perfect.”
Then they dined on beef short rib confit with sweet and sour crispy pork.
As they emerged from the meal for a brief stroll together, Mr Trump appeared to delight in showing his North Korean counterpart the interior of “The Beast”, his famed presidential limousine known for its high-tech fortifications.
Critics of the summit leapt at the leaders’ handshake and the moonlight stroll Mr Kim took on Monday night along the glittering Singapore waterfront, saying it was further evidence that Mr Trump was helping legitimise him on the world stage.
Mr Trump responded on Twitter, saying: “The fact that I am having a meeting is a major loss for the U.S., say the haters & losers.”
But he added “our hostages” are back home and testing, research and launches have stopped.
The optimistic summit was a remarkable change in dynamics from less than a year ago, when Mr Trump was threatening “fire and fury” against Mr Kim, who in turn scorned the American president as a “mentally deranged US dotard”.
Beyond the impact on both leaders’ political fortunes, the summit could shape the fate of countless people — the citizens of impoverished North Korea, the tens of millions living in the shadow of the North’s nuclear threat, and millions more worldwide.