Secretary of State John Kerry spoke with Yahoo's Katie Couric about the possibility of collaborating with the Iranian government to halt advances by ISIS in Iraq. In the interview, Secretary Kerry said that U.S. airstrikes in Iraq remain an option to combat the terrorist group. (Yahoo News)

Iran and the United States are starting to signal a cautious willingness to work together, reflecting their shared interest in protecting the fragile Iraqi government against al-Qaeda-inspired fighters and, more broadly, in preserving regional stability.

U.S. Secretary of State John F. Kerry suggested Monday that Washington has not ruled out such cooperation.

“I think we are open to any constructive process here that could minimize the violence, hold Iraq together — the integrity of the country — and eliminate the presence of outside terrorist forces that are ripping it apart,” he said.

Kerry’s comment echoed remarks Saturday by Iran’s president, Hassan Rouhani, who said Iran would consider working with its longtime enemy if the United States became involved in the fight.

Iranian and U.S. diplomats discussed the possibility of cooperation during meetings in Vienna on Monday about limits to Iran’s nuclear program, a State Department official said.

The United States and Iran find themselves on the same side of the current battle in Iraq, both seeking to prevent the collapse of the Baghdad government or descent into all-out civil war. That convergence is uncomfortable for both nations, coming after years of U.S. allegations that Iran furnished explosives and know-how to insurgents fighting U.S. forces in Iraq.

It also contrasts with the situation in Iran’s neighbor Syria, where the United States is supporting rebels seeking the ouster of the Iranian-backed government.

The Obama administration has not decided whether to launch airstrikes against the Sunni Arab militia that has laid claim to a string of cities in Iraq’s north and west.

U.S. officials stressed that neither Washington nor Tehran is considering a military alliance, something that would be awkward or impossible given the history of enmity.

State Department spokeswoman Jen Psaki said any discussion or cooperation with Iran would be similar to the practical cooperation the two countries applied to Afghanistan a decade ago.

“We’re not talking about coordinating any military action in Iraq with Iran. We would encourage Iran to push the Iraqis to act to address problems in a nonsectarian way,” Psaki said.

How the Islamic State is carving out a new country

Pentagon press secretary Rear Adm. John Kirby told reporters that any cooperation would be limited and diplomatic, not military.

“There is absolutely no intention and no plan to coordinate military activities between the United States and Iran.”

Iranian officials voiced similar sentiments.

“If the issue is about confronting extremism and violence, then yes, we’re on the same side, but if it’s about destabilizing the region, then, no we are not,” said Hesameddin Ashna, an adviser to Rouhani and head of the Center for Strategic Studies, a government-run think tank.

Ashna said, however, that while Iran would not support a U.S. ground intervention and is glad that President Obama has said he is not considering it, airstrikes could provide much-needed assistance to the “paralyzed” Iraqi air force.

Iraqi Prime Minister Nouri al-Maliki has asked for U.S. military help, with the implicit threat that he could turn increasingly to Iran if the United States does not come through.

Several of Rouhani’s ministers and advisers said Monday they would prefer to see Maliki’s government deal with the onslaught from the Islamic State of Syria and Iraq (ISIS) by itself.

“We do not feel any need to cooperate with the United States over developments in Iraq," Hossein Amir-Abdolahian, Iran’s deputy foreign minister for Arab and African Affairs said Monday, according to the semiofficial Mehr News Agency.

As in Washington, some influential voices here opposed even a short-term alliance between Iran and the United States.

Hossein Shariatmadari, editor of the ultra-conservative Kayhan newspaper and a vehement opponent of rapprochement with the United States, said it was “unrealistic” to think that the two states could successfully work together and accused the United States of having funded ISIS rebels in Syria.

“Whatever the causes, we have to get this crisis under control as soon as possible,” Shariatmadari said. “The Iraqis don’t have enough experience in fighting terrorism, and Iranian experience can help, just as it has been helpful to the Syrians.”

Another group that could play a pivotal role in the conflict is Iran’s population of Iraqi Shiites who fled their country during Saddam Hussein’s rule, hundreds of thousands of whom have made Iran their permanent home.

Since 2003, many have renewed ties with their homeland and have commercial and religious interests at stake if the country falls to ISIS forces.

Gearan reported from Washington.