In an address at the annual summit of the Shanghai Cooperation Organisation, Rouhani said the US has been trying to impose its policies on others countries which was a kind of warning for all the major powers.
"The US unilateralism was not good for the world. We have the recent example of US unilateralism and its defiance of the international community when the US pulled out from the JCPOA," he said.
In his address, Chinese President Xi Jinping also made a veiled dig at the US for withdrawing from the deal, noting that China was willing to work with Russia and other countries to protect the deal.
Russian President Vladimir Putin too sounded critical of the US decision, saying the move may destabilise the Gulf region.
Iran had struck the JCPOA (Joint Comprehensive Plan of Action) deal with the US, the UK, Russia, China, France and Germany after years of negotiations.
US President Donald Trump last month announced that the US was withdrawing from the Iran nuclear deal signed by the Obama administration in 2015 under which Tehran had agreed to limit its nuclear activities and allow in international inspectors in return for the lifting of crippling economic sanctions.
Several European countries as well as China and Russia have been trying to save the deal.