Iran’s president, Hassan Rouhani, urged the United States on Monday to “stop invading” the Middle East, and he said that the new American emphasis on diplomacy could help to “return stability’’ to Syria.

The comments by Rouhani were the first since the United States and Russia struck a deal during the weekend to reduce Syria’s stockpile of chemical weapons. The Iranian leader made clear that he welcomed the deal, but he also used the moment to warn Washington and its allies against any further use of force.

“The U.S. and Europe know the gruesome effects of war in this region,’’ Rouhani said. “They know that they did not achieve their goals in previous wars.’’ As for Syria, he said: “We are happy that a war has been averted and will do our best to make sure one does not begin.’’

Rouhani was speaking to commanders of Iranian Revolutionary Guard Corps. The Iranian leader, who took office last month, has signaled a desire to improve relations with the West, but his comments served as an indication that longstanding mistrust between Washington and Tehran will not diminish easily.

The remarks came a day after President Obama acknowledged that he and Rouhani had corresponded by letter in recent weeks. They also came after a visit to Israel in which Secretary of State John F. Kerry assured leaders that the United States remained determined to curb an Iranian nuclear program that Washington says is aimed at producing nuclear weapons.

In remarks that he directed at the United States, Rouhani said: “You are uninvited guests. Stop invading the region. You must not practice Iranophobia. We do not need your intervention.’’

Rouhani also dismissed the oft-repeated claim that Iran wants to replace U.S. allies, Israel and Saudi Arabia, as the Middle East’s main military power. Leaders of those and other Arab countries say a more powerful Iran threatens regional security.

“The mistake of the West is that they think Iran is looking for an opportunity to rule over the region. We do not want to have military rule over the region and if we are powerful today our strength is through dialogue,” Rouhani said.

Rouhani will travel to New York later this week to attend the annual United Nations General Assembly, where members of his foreign policy team are scheduled to meet with several top European officials including British Foreign Secretary William Hague and Catherine Ashton, the European Union’s foreign policy chief, who leads the P5+1 negotiating team in their ongoing nuclear talks with Iran. The P5+1 consists of the five permanent members of the U.N. Security Council (the United States, Russia, China, the United Kingdom and France) plus Germany.

Iran is Syria’s closest ally, and it has provided support to Syrian forces and to the Lebanon-based Hezbollah militia in the civil war that pits the Damascus government against a loose and divided grouping of rebel forces.

Iran has insisted that rebel forces, and not the Syrian government, were responsible for the Aug. 21 chemical attack in a Damascus suburb.

“We are against chemical weapons and condemn their use by anyone, anywhere. Our goal is to return stability to Syria,” Rouhani said.