BIARRITZ, France — President Trump shifted his tone on the trade war with China yet again on Monday, expressing confidence that the two sides can reach a deal and calling President Xi Jinping a “great leader” three days after branding him an “enemy.”

As he completed an international summit meeting, Mr. Trump told reporters that Chinese officials had reached out by telephone and that negotiators would restart trade talks after the latest escalation in tariffs and his “order” to American companies to look for ways to pull out of China.

In another surprise, Mr. Trump said he was open to meeting with President Hassan Rouhani of Iran within the next few weeks in response to an initiative by President Emmanuel Macron of France. Such a meeting would be the first between American and Iranian leaders since the Tehran hostage crisis of 1979-81.

The change in the president’s language about China was especially striking given his hard-line approach over the last few days, and it seemed to reassure markets rattled by the latest escalation of tariffs on Friday. But it was not clear how concrete an opening China really had made.