Speaking during a National Army Day parade in which Iranian forces displayed sophisticated air defence systems recently acquired from Russia, Rouhani praised Tehran's role in helping the Syrian and Iraqi governments roll back the Islamic State group.
"If tomorrow your capitals face danger from terrorism or Zionism, the power that will give you a positive answer is the Islamic Republic of Iran," he said. But he added that Iran would only help if Muslim countries asked it to, and said its military power was purely for defensive and deterrent purposes.
He appeared to be referring to Gulf Arab states, which have long viewed Iran as seeking to dominate the region. Saudi Arabia and Iran are longtime rivals that back opposite sides in the Syrian and Yemeni civil wars.
During the parade, the army displayed Russian-made S-300 air defence missiles delivered earlier this month.
More From This Section
In 2010, Russia froze a deal to supply the sophisticated systems to Iran, linking the decision to UN sanctions.
President Vladimir Putin lifted the suspension last year following Iran's deal with six world powers that curbed its nuclear programme in exchange for relief from international sanctions.
Iran also displayed tanks, light submarines, short-range missiles and other weapons.