The White House scrambled to lend a veneer of coordination to Mr. Trump’s outburst. Officials said it had come after consultations with the national security adviser, John R. Bolton, and in response to statements by Iran’s president, Hassan Rouhani. A senior administration official said it augured a “more aggressive, comprehensive approach” to Iran.

Other people who know Mr. Trump said his decision to respond in such fiery terms was driven almost entirely by his search for a distraction from questions about Russia. Mr. Rouhani’s words were hardly unusual, they noted: He warned the United States against the “mother of all wars” with Iran, but also opened the door to the “mother of all peace.”

There was nothing in Mr. Trump’s tweet to suggest he is looking to talk anytime soon. But his words carried a distinct echo of his threat last summer to North Korea’s leader, Kim Jong-un, whom he said faced “fire, fury and frankly power, the likes of which this world has never seen before.”

Eight months later, Mr. Trump accepted Mr. Kim’s invitation to meet, and after spending a few hours with him in Singapore, Mr. Trump declared that he and Mr. Kim had ended the nuclear crisis with North Korea. He has stuck to that assessment despite the fact that North Korea pledged to do nothing beyond what it has long promised, and that subsequent negotiations have bogged down in mutual recrimination.

When Mr. Trump withdrew the United States from the Iran nuclear deal in May, he told aides and foreign leaders that his policy of maximum pressure had forced Mr. Kim to the bargaining table, and that a similar policy of overwhelming pressure would enable the United States to extract a better deal from Iran.