BEIJING — He came bearing gifts, including a brown horse named Vesuvius plucked from the French presidential cavalry. He tried his hand at Mandarin. He journeyed to an ancient capital to pay respects to China’s first emperor.

President Emmanuel Macron of France, during a three-day visit to China this week, has worked at every turn to win over China’s leaders, hoping to reinvigorate ties between the two countries as they grapple with the strident nationalism of President Trump.

Mr. Macron and President Xi Jinping, during meetings this week, articulated a vision sharply at odds with Mr. Trump’s worldview. They spoke of a need for free trade and rallied against protectionism. They embraced multilateralism and praised institutions like the United Nations.

And they emphasized the importance of working together to combat climate change, as the United States backs away from global efforts to reduce the emission of greenhouse gases.