Many Iranians have expressed astonishment and ridicule at such assertions, pointing to terrorist groups that despise Iran and the West. First Al Qaeda, responsible for the Sept. 11, 2001, attacks, and more recently the Islamic State, which has been killing thousands in the Middle East and is responsible for committing and inspiring attacks in Europe and the United States.

“Trump is trying to corner Iran, to make us bow before the U.S. and change our behavior, or face confrontation,” said Nader Karimi Joni, a political activist close to Mr. Rouhani’s government.

Mr. Trump included Iran on a list of seven predominantly Muslim countries whose citizens have been barred from entering the United States under an executive order that has been blocked, for now, in the American court system. Mr. Trump’s national security adviser, Michael T. Flynn, warned Tehran last week that it had been put “on notice” after an Iranian missile test.

Washington imposed new economic sanctions on 25 people and entities after the missile launch, which Mr. Flynn said had violated a 2015 United Nations Security Council resolution approved after the United States and other world powers reached an agreement with Iran on its nuclear program. Iran has asserted that its missile tests do not violate that resolution and fall within its rights to self-defense.

In another possible move against Iran, Mr. Trump’s advisers are debating an order intended to designate its Islamic Revolutionary Guards Corps as a foreign terrorist organization, according to current and former officials in the United States briefed on the deliberations.

For Ayatollah Khamenei, Mr. Trump’s ascent appears to have vindicated many suspicions harbored by the Iranian leader, who has said many times that the United States cannot be trusted.

“He has proven what we have been saying for more than 30 years — we would always speak about the political, economic, moral and social corruption in the U.S. administration — this man revealed it during the election campaign and since then,” Ayatollah Khamenei said, according to a translated text of the speech.