Behind closed doors, administration officials insisted, Iran was still the primary subject of conversation. But whether out of comfort with talking about another deal or a simple desire to be unpredictable, Mr. Trump managed to reframe the meeting as being about an issue that neither the United States nor Israel had any intention to push at the General Assembly.

On Iran, too, Mr. Trump showed he liked keeping people guessing. Speaking to reporters on Wednesday, he said, “I have decided” what to do about the Iran nuclear agreement, which he has long derided as terrible. Then he would not tell them what the decision was.

Later, when Mr. Trump met with Prime Minister Theresa May of Britain, she asked him what his decision was. He would not tell her either. “Prime Minister May asked him if he would share it with her and he said no,” Secretary of State Rex W. Tillerson told reporters.

Mr. Tillerson, betraying the slightest hint of exasperation, added that he knew Mr. Trump had arrived at a decision but did not expect him to share that information with the public.

On his first foreign trip, Mr. Trump was mild-mannered in the Middle East and blunter in Europe. In New York, the polite president of Day 1 was replaced by a fire-breathing version on the second day, inveighing against Iran, Venezuela and North Korea. To some longtime American diplomats, Mr. Trump’s performance was offensive.

“When he declared to the world’s leaders that he was embarrassed by the Iran nuclear deal negotiated by his presidential predecessor, I felt he shamed America and thereby shamed himself,” said Martin S. Indyk, who served as ambassador to Israel under President Bill Clinton and as a Middle East envoy under President Barack Obama.

To some in the room, however, Mr. Trump’s emphasis on sovereignty and the sovereign rights of nations resonated.