His comments came after Saudi Crown Prince Mohammed bin Salman accused Iran of delivering missiles to Yemeni rebels for use against targets in the kingdom that he described as 'direct military aggression'.
Iran has strongly denied supplying any missiles to the rebels, saying that it would have been impossible to do so in any case in the face of a Saudi-led air and sea blockade.
Tehran has hit back against the increasingly fierce rhetoric from Riyadh with strong words of its own, troubling international oil markets.
'You know the might and place of the Islamic republic. People more powerful than you have been unable to do anything against the Iranian people,' Rouhani said at a cabinet meeting in remarks aimed at Saudi leaders.
'The United States and their allies have mobilised all their capabilities against us and achieved nothing.'
Rouhani referred to the Iran-Iraq war of 1980-88, in which revolutionary Iran successfully resisted an invasion by Saddam Hussein's regime supported by Gulf Arab and Western governments.
Rouhani reiterated that Iran wanted a peaceful settlement of the conflict between the rebels and the Saudi-backed Yemeni government, and of other wars around the region that have placed it at loggerheads with Riyadh.
'We want the welfare and development of Yemen, Iraq and Syria, and of Saudi Arabia too. There are no other paths forward than friendship, brotherhood and mutual assistance,' he said.
'If you think that Iran is not your friend and that the United States and the Zionist regime (Israel) are, you are making a strategic and analytical error.'
US support for Saudi
Trump's administration was quick to express support for the kingdom's claims that Iran has supplied missiles to the rebels.
The White House called for a UN inquiry into the origins of the rebels' ballistic capabilities that on Saturday saw them fire a missile more than 800 kilometres (500 miles) to near Riyadh international airport where it was intercepted and destroyed by Saudi air defences.
'These missile systems were not present in Yemen before the conflict, and we call upon the United Nations to conduct a thorough examination of evidence that the Iranian regime is perpetuating the war in Yemen to advance its regional ambitions,' it said.
Rouhani asked what alternative the rebels had in the face of the devastating bombing campaign waged against them by the Saudi-led coalition since March 2015.
'You... constantly bomb the Yemenis... but when for once they fire back, you say it's unjust. What are the Yemeni people supposed to do?' he asked.
The Iranian president suggested that the tougher foreign policy line from the Saudi crown prince might be a reflection of the internal upheaval he triggered by ordering the arrest of dozens of princes, ministers and a tycoon last weekend.
'If Saudi Arabia is experiencing domestic problems, it needs to settle them and not to try to create problems for the other peoples of the region and speak out against them,' he said.
Foreign Minister Mohammad Javad Zarif tweeted a call on Wednesday for a peaceful solution to be found over Yemen, not 'new crises by bombings, threats'.
'There's no crisis that diplomacy can't resolve. We proved that once,' Zarif wrote of the nuclear deal Iran reached with world powers in 2015.
Also Wednesday, the conservative Iranian daily Kayhan was given a two-day suspension for Monday's front-page headline 'Ansar Allah (Yemen's Huthi rebels) fire missile at Riyadh: the next target will be Dubai'.
The official IRNA news agency said Iran 's Supreme National Security Council ruled that the headline was 'contrary to the Islamic republic's policy in the region'.