"If American officials think that they can pressure Iran by walking out of the deal, they are making a big mistake", he added.
President Donald Trump said on Wednesday that he has made up his mind on whether to scrap the Iran nuclear agreement, but declined to say what his decision was.
Rouhani's comments came a day after Trump's speech to the United National General Assembly, in which he castigated the Iranian government for masking "a corrupt dictatorship behind false guise of a democracy".
"Ugly, ignorant words were spoken by the US president against the Iranian nation", said Rouhani in his own speech to the General Assembly, "full of hatred and baseless allegations".
"Well, I have decided", Trump told reporters who pressed him for an answer before they were escorted out of his meeting with Mahmoud Abbas, president of the Palestinian Authority.
He responded to Donald Trump's Tuesday address, which fiercely criticised Iran, calling it "ignorant, absurd and hateful rhetoric" that was "unfit to be heard at the United Nations".
Addressing the General Assembly, Rouhani said his country won't be the first to violate the nuclear agreement "but it will respond decisively to its violation by any party".
"The world will have lost a great opportunity", he declared.
The U.S. president must decide by October 15 whether to certify that Iran is complying with the pact, a decision that could sink the deal.
Rouhani continued by defending his country's participation in the nuclear agreement and offered a threat directed towards the USA, saying that Iran "will respond decisively and resolutely to its violation by any party". If the president doesn't certify compliance, Congress has 60 days to decide whether to re-impose sanctions lifted under the agreement.
"As such, it belongs to the global community in its entirety and not only to one or two countries".
"It has turned a wealthy country with a rich history and culture into an economically depleted rogue state whose chief exports are violence, bloodshed and chaos", Trump said, repeating a litany of oft-spoken US complaints.
In a speech that was clearly meant to position Iran as a moderating force and member of the worldwide community - despite criticism of its support for terrorism and regimes such as Bashar al-Assad's Syria - Rouhani held up the Joint Comprehensive Plan of Action, as the Iran deal is known, as evidence of Tehran's aim to cooperate and engage with the world.
The rhetorical threats have anxious the other countries in the agreement: Britain, China, France, Germany and Russian Federation.
French President Emmanuel Macron told reporters in NY "it would be a mistake to annul the nuclear agreement without anything else".
Iran rejects the idea that it has broken the agreement, and a United Nations report this month pointed to no Iranian violations.