"Today, the largest power against intimidation and terror is our armed forces," Rouhani said at a massive military parade in Tehran.
Iran has played a major role in the fight against the Islamic State group in neighbouring Iraq independently of the US-led coalition.
It has provided military advisers, weapons and trainers to both the Iraqi army and Shiite militias.
But Rouhani's allusion was not only to the jihadists of IS.
Signup to our newsletter and follow us on Facebook and Twitter!
In the conflict in Syria, Tehran has been a staunch ally of the regime of President Bashar al-Assad against Western-backed rebels as well as IS and Al-Qaeda.
"We helped the armies and governments of Iraq and Syria, at their request," Rouhani said.
"If terrorists start showing up in other regional countries, their only hope is Iran's army, the Revolutionary Guards, and the Basij (militia).
"They shouldn't think that Western or world powers would defend them."
The parade marked the 35th anniversary of the start of Iran's devastating 1980-1988 war with Saddam Hussein's Iraq and Rouhani's speech was screened live on state television.
Iran has been deeply critical of the US-led campaign against IS, charging that it was the support of the West and its allies for the rebellion in Syria that paved the way for the rise of the jihadists.