By Parisa Hafezi

ANKARA (Reuters) - Shi'te Muslim Iran is so alarmed by Sunni insurgent gains in Iraq that it may be willing to cooperate with Washington in helping Baghdad fight back, a senior Iranian official told Reuters.

The idea is being discussed internally among the Islamic Republic's leadership, the senior Iranian official told Reuters, speaking on condition of anonymity. The official had no word on whether the idea had been raised with any other party.

Officials say Iran will send its neighbor advisers and weaponry, although probably not troops, to help its ally Prime Minister Nuri al-Maliki check what Tehran sees as a profound threat to regional stability, officials and analysts say.

Islamist militants have captured swathes of territory including the country's second biggest city Mosul.

Tehran is open to the possibility of working with the United States to support Baghdad, the senior official said.

"We can work with Americans to end the insurgency in the Middle East," the official said, referring to events in Iraq.

"We are very influential in Iraq, Syria and many other countries."

For many years, Iran has been aggrieved by what it sees as U.S. efforts to marginalize it. Tehran wants to be recognized as a significant player in regional security.

COMMON CAUSE

Relations between Iran and Washington have improved modestly since the 2013 election of President Hassan Rouhani, who promised "constructive engagement" with the world.

And while Tehran and the United States pursue talks to resolve the Islamic state's decade-old nuclear standoff with the West, they also acknowledge some common threats, including the rise of al Qaeda-style militancy across the Middle East.

On Thursday, President Barack Obama said the United States was not ruling out air strikes to help Baghdad fight the insurgents, in what would be the first U.S. armed intervention in Iraq since the end of the U.S.-led war.

Rouhani on Thursday strongly condemned what he called violent acts by insurgent groups in the Middle East.

Story continues

“Today, in our region, unfortunately, we are witnessing violence, killing, terror and displacement," Rouhani said.

"Iran will not tolerate the terror and violence ... we will fight against terrorism, factionalism and violence.”

Asked on Thursday about Iranian comments, U.S. State Department spokeswoman Jen Psaki said: "Clearly, we've encouraged them in many cases to play a constructive role. But I don't have any other readouts or views from our end to portray here today.”

Fearing Iraq's war could spill into Iran, Foreign Minister Mohammad Javad Zarif has urged the international community to back Maliki's administration "in its fight against terrorism".

Brigadier-General Mohammad Hejazi said Iran was ready to supply Iraq with “military equipment or consultations,” the Tasnim news agency reported. "I do not think the deployment of Iranian troops would be necessary," he was quoted as adding.

The senior Iranian official said Iran was extremely worried about the advance of ISIL, also a major force in the war against Iran's close ally Syrian President Bashar al-Assad, carving out a swathe of Syria territory along the Iraqi border.

"The danger of extremist Sunni terrorist in Iraq and the region is increasing ... There have been several high-ranking security meetings since yesterday in Tehran," the official said.

"We are on alert and we also follow the developments in Iraq very closely."

(Additional reporting by Michelle Moghtader in Dubai, Writing by Parisa Hafezi, Editing by William Maclean and Janet McBride)