Francis left no doubt about his message in the gifts he gave to his guest, notably the essay on the importance of the environment, which stands as a rebuke to the climate change skepticism espoused by Mr. Trump. Francis also presented him with a medallion engraved with the image of an olive tree — “a symbol of peace,” he explained. “We can use peace,” Mr. Trump said. Francis replied, “It is with all hope that you may become an olive tree to make peace.” As he bade the pope farewell, Mr. Trump told him, “I won’t forget what you said.”

For Mr. Trump, who came here after stops in Saudi Arabia and Israel, the visit to the Vatican capped a tour of the ancestral homes of three of the world’s great monotheistic religions. For Francis, who made his own landmark visit to Egypt last month, it was a chance to welcome a second American leader, after President Barack Obama paid his respects in 2014. Unlike that meeting, few expected a meeting of the minds. Pope Francis and Mr. Trump have diametrically opposed views on issues like immigration, climate change and arms sales. Although both appeared determined not to let politics spoil their encounter, their fraught personal history and divergent personal styles made for a loaded backdrop.

In Saudi Arabia, Mr. Trump came with a $110 billion arms deal and was embraced by a royal family eager to improve relations with Washington. In Israel, he expressed America’s solidarity with a close ally and staked his claim as a peacemaker. At the Vatican and elsewhere in Europe, however, Mr. Trump has had to overcome suspicions.

At 8:20 a.m., under an azure sky, the president’s motorcade rolled into the courtyard of the Apostolic Palace. Swiss Guards stood at attention as Mr. Trump and his wife, Melania, stepped out of a sport utility vehicle — he in a dark suit, she in a black dress with a veil on her hair. A few minutes earlier, the pope arrived in a lone blue Ford Focus.

Archbishop Georg Gänswein, the prefect of the papal household, greeted Mr. Trump and escorted him to an antechamber outside the pope’s office, where, after a few seconds, Francis came to greet him. “Thank you so much,” Mr. Trump said. “It’s an honor.”

After posing for a picture — “protocol,” the pope murmured — Mr. Trump took a seat across a wooden desk from Francis. Vatican officials shooed reporters out of the room and the two men met for half an hour (the pope’s session with Mr. Obama lasted 20 minutes longer). Speaking to reporters later, Mr. Trump described the session as “fantastic.” Later, on Twitter, he wrote, “I leave the Vatican more determined than ever to pursue PEACE in our world.”