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 -
US President Donald Trump has taken a much tougher line against Iran than his predecessor Barack Obama, emboldening Saudi Arabia and its allies.
US ambassador to the United Nations Nikki Haley accused Iran of supplying a missile to Huthi rebels that was fired into Saudi Arabia in July.
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.
"Huthi missile attacks against Saudi Arabia, enabled by Iran's Islamic Revolutionary Guard Corps, threaten regional security and undermine UN efforts to negotiate an end to the conflict."
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.
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)