SAINT-JEAN-DE-LUZ, France — At the end of last year’s meeting of America’s closest allies, President Donald Trump cut out early to meet with North Korean dictator Kim Jong Un, bashing the Canadian prime minister on Twitter on his way out the door.

Trump ended this year’s gathering with a bear hug for French President Emmanuel Macron and a declaration of unity among the allies. Not even a surprise visit by the Iranian foreign minister the day before, staged by Macron to portray himself as the world’s chief diplomat, could break Trump’s feeling of camaraderie.

“If there’s any word for this particular meeting of seven important countries, it’s unity,” he said Monday at a press conference, just before heading back to Washington. “We got along great.”

The summit may have ended with a similar policy gap as last year's, with little by way of concrete results — except for one that could pay long-term dividends for some of those present: World leaders seem to have figured out how to deal with a president like Donald Trump.

Trump sounded familiar notes while in the French seaside town, with praise for traditional U.S. adversaries and criticism of his predecessor. He said that President Barack Obama had been “outsmarted” by Russian President Vladimir Putin and that Obama had caused Russia to be kicked out of the group when in fact it was a multinational decision. At the same time, he called Chinese President Xi Jinping a “brilliant” leader.

And he maintained his stream of self-promotion, talking up his Doral golf resort in Florida, where he said the U.S. will likely hold the Group of Seven meeting next year, while again alleging he is sacrificing billions of dollars to serve as president.

But he held his punches when it came to the leaders of the six other countries in attendance and avoided making himself the focus of the event. Even on Twitter he was uncharacteristically restrained, mostly sending out congratulations and well-wishes to his allies.

Trump barreled into the meeting waging a trade war with China and threatening another with Europe, even suggesting before arrived in France that he’d put a tax on French wine in retaliation for a tax the country out on internet sales.

But the tone quickly shifted after an impromptu lunch with Macron, who organized the meeting. Moments after Trump got off Air Force One, Macron “lassoed” him, possibly keeping Germany’s Angela Merkel waiting, said economy adviser Larry Kudlow. The next morning, Macron scheduled a meeting among all the leaders to discuss trade — a topic Trump had specifically requested be a focus.

“I give Macron a lot of credit,” Kudlow told reporters Sunday.

U.K. Prime Minister Boris Johnson also credited Macron with navigating the choppy diplomatic waters. In a break between meetings Sunday afternoon, cameras caught Johnson congratulating Macron on his handling of the dinner the night before.

"Well played," Johnson told Macron. "You did very well last night.”

Meanwhile, Macron’s wife, Brigitte, led first lady Melania Trump and the other spouses on a tour around Southern France, sampling sangria and taking in a local choir performance.

Since the first day, Trump has sought to emphasize the camaraderie and good relations among the leaders — and particularly sought to play up his relationship with Macron, saying their 90-minute lunch was one of the best periods of time they'd spent together and that the U.S. was treated “beautifully” at the summit.

There were no shortage of disagreements among Trump and the other world leaders on trade, Iran, North Korea and climate change.

Trump and Japanese Prime Minister Shinzo Abe disagree on whether North Korea was in breach of any agreements with recent missile launches. Johnson said he disagreed with Trump’s use of tariffs and favored trade peace over a trade war.

But the divisions, when expressed publicly, were done so with deference.

Even a last-minute visit from Iran’s foreign minister couldn’t agitate Trump. While White House staff were blindsided by the arrival of Iranian Foreign Minister Mohammad Javad Zarif, Trump said Macron kept him informed about every piece of the visit.

Trump didn’t attend the group’s meeting on climate change — an area Macron wanted to be a focus of the summit. The White House said Trump had scheduled other meetings instead during that time and sent staff in his place, and Macron downplayed Trump’s absence.

Macron also sidestepped the possibility of confrontation by scrapping the traditional signing of a joint statement because he knew Trump wouldn't be on board. At last year's G-7 summit, Trump withdrew his endorsement of a joint statement on climate change at the end of the gathering.

And while Canada's Justin Trudeau ignited a Twitter tirade from Trump after that meeting by holding a press conference critical of Trump's stance on trade, Macron's approach offered far more presidential appeal.

When asked at a press conference about his relationship with Trump at the end of the summit, Macron offered praise for his U.S. counterpart.

"He works hard for his country," he said.