He made the remarks when asked if mutual interest could possibly bring Iran and the US together, despite their lack of diplomatic relations for more than three decades.
Rouhani left the door open to some form of joint intervention after noting that Iran was worried about security in the region, and after acknowledging his country's "close and intimate" relations with Iraq.
"If we see that the United States takes action against terrorist groups in Iraq, then one can think about it," he said.
Rouhani and US President Barack Obama have separately pledged support for Iraqi Prime Minister Nuri al-Maliki's government in fighting advancing militants from the Islamic State of Iraq and the Levant (ISIL).
More From This Section
Maliki's security forces are reportedly preparing a counter attack after losing the cities of Mosul and Tikrit, where some units discarded their uniforms and abandoned their positions. ISIL has not been contained.
However, dismissing reports that Iran has already sent troops across the border, Rouhani said no specific request for help has been made by Maliki, stressing that such a decision is Iraq's to make.
Yesterday, Obama said a range of options short of sending troops was being considered, but he suggested that Iraq must take steps to heal its sectarian divide.
In Tehran, Rouhani said contact with the US leadership would be possible if deemed necessary, a task almost unheard of before the self-declared moderate took office in August last year.
But signalling that Iran is not at one with the US over the regional situation, Rouhani hit out at Western and Arab governments for backing rebels fighting to overthrow Syrian President Bashar al-Assad, an Iran ally, arguing that the jihadist surge in Iraq was a spillover from that conflict.