“The Trump administration condemns actions by Iran that undermine security, prosperity and stability throughout the Middle East and place American lives at risk,” Mr. Flynn said on Wednesday.

Later that day, Mr. Trump said on Twitter that “Iran is rapidly taking over Iraq,” its neighbor, even after “the U.S. squandered three trillion dollars there. Obvious long ago.”

During the presidential campaign, Mr. Trump spoke favorably of unpredictability in foreign policy, pointing to the Reagan presidency as an example of the benefits of keeping opponents off balance. Since taking office, he has been good to his word, and Iranians have noticed.

“Trump is not predictable for Americans, not for Europeans and not for us,” said Nader Karimi Joni, an analyst close to the government of President Hassan Rouhani. “He and his team are not trustworthy. They will not honor any agreement. Nothing good is coming from this.”

Certainly not for Mr. Rouhani, a moderate who came to power promising to ratchet down tensions with the West, cinch a nuclear deal and get Iran’s economy moving again. Now, all those goals are in jeopardy, and Mr. Rouhani’s re-election this spring is far from assured.

On Thursday, an aide to Iran’s supreme leader, Ayatollah Ali Khamenei, called Mr. Trump’s remarks “hollow rants” and said that they “would bring losses for his country’s national interest.” And a former foreign minister, Ali Akbar Velayati, said that Iran would continue to test missiles.

Mr. Rouhani has called Mr. Trump a political novice. But there is little doubt that the clerics have been thrown off balance. One analyst with access to government deliberations said that hard-liners in Iran were confused and did not know how to deal with the situation. Some in the establishment are opting for the same rhetoric and tactics they used under Mr. Obama, but in reality, this is uncharted territory, he said.