PARIS — With a warm clasping of hands, President Trump and President Emmanuel Macron of France cemented an unlikely but budding relationship on Friday, capped by a Bastille Day military parade in Paris meant to emphasize the alliance between the United States and its oldest ally.

Despite some wariness in the initial contacts between Mr. Trump, 71, and Mr. Macron — who at 39 is the same age as Mr. Trump’s eldest son, Donald Trump Jr. — the American leader’s two-day visit to France ended on a high note.

Mr. Trump had publicly supported Mr. Macron’s far-right opponent, Marine Le Pen, in France’s presidential elections. Mr. Trump and Mr. Macron have sharply differing views on a range of issues, most notably the Paris accord, the climate change pact that Mr. Trump renounced six weeks ago.

But Mr. Macron and his wife, Brigitte, beguiled Mr. Trump and his wife, Melania, with red-carpet treatment and catered to Mr. Trump’s well-known penchant for military displays of power, which were woven into the Bastille Day parade they attended before flying home. It was Mr. Trump’s first visit to France as president.