The nation's top military official, however, said the Islamic Republic had no intention of deploying troops to Iraq.
Rouhani spoke of protecting the shrines during a visit to western Lorestan province.
"We announce for all superpowers and their hirelings, murderers and terrorists, that the great Iranian nation will spare no efforts to protect the glory of the holy shrines," Rouhani told a crowd, according to an account from BBC Monitoring, which translates foreign news reports.
The president’s speech appeared to be largely symbolic in nature since he has already declared that Iran was unlikely to dispatch forces to Iraq to assist the Shiite-led government of Prime Minister
In a separate speech Wednesday, Major Gen. Hassan Firouzabadi, chief of staff of the Iranian armed forces, said Iran had no intention of deploying troops to Iraq. The Iraqi government, the general said, was capable of dealing with the threat from Sunni militants who last week overran large stretches of territory in northern and central Iraq.
"There is no need for the presence of Iranian forces in Iraq," Firouzabadi said, according to Press TV, Iran's official English-language news service.
Iran already provides logistical aid and other support to Iraqi government, Western diplomats say.
Like other Iranian officials, the general dismissed the idea that the United States and Iran would work together to back the Maliki government in Baghdad. Both Washington and Tehran support the Maliki administration against the threat from militant Sunni Islamists. But the prospect of U.S.-Iranian cooperation in Iraq has drawn opposition in both nations.
Iraq is home to some of Shiite Islam's most sacred sites, including landmark mosques in the cities of Najaf, Karbala, Samarra and in the Baghdad district of Kadhimiya. Tens of thousands of Iranian pilgrims travel annually to Iraq to visit the Shiite holy sites. For years, Sunni militants in Iraq have targeted Shiite pilgrims in deadly attacks.