WASHINGTON (Reuters) - Iran may pose the greatest long-term threat to Iraq’s stability, a U.S. general said on Tuesday, the day after Iran’s president wrapped up a visit to Baghdad.

Army Lt. Gen Ray Odierno, who recently ended a 15-month assignment as the No. 2 U.S. commander in Iraq, said Iran continued to train extremist militia groups in Iraq.

Odierno also said he was not surprised Iranian President Mahmoud Ahmadinejad was able to move around without security problems during his two-day visit to Baghdad as the groups that often target high-profile visitors are Iranian-backed.

“Over the last 12 months, every time a visitor would come from the United States, we’d either foil a rocket attack or the rocket attack happened. And guess what? That’s because it was being done by Iranian surrogates,” Odierno said.

“And when the government of Iraq holds a meeting, there tends to be rocket attacks. Why’s that? Because it’s done by Iranian surrogates,” he told reporters at the Pentagon.

The U.S. military has repeatedly accused Iran of training, supplying and funding Shi’ite militias in Iraq. Iran has denied the accusations.

Ahmadinejad’s visit was the first to Iraq by an Iranian president since the two countries fought an eight-year war in the 1980s in which 1 million people were killed.

Iraq’s Shi’ite-led government has sought good relations with Iran, another Shi’ite majority country.

But Odierno said he believed Iran wanted Iraq to have only a weak government.

Despite a substantial drop in violence since last summer, U.S. forces in Iraq still face many challenges, including the threat from Sunni insurgent group al Qaeda in Iraq.

Odierno singled out Iran as a factor of particular concern.

Asked if he saw Iran as the greatest long-term threat to Iraq’s stability, he said: “If you ask me what I worry about most, I do. I do worry about that as a long-term threat.”

Odierno said he had mentioned Iran in discussions with President George W. Bush at the White House on Monday.

Iran's President Mahmoud Ahmadinejad attends a ceremony before leaving for Iraq, at the International Mehrabad Airport in Tehran, March 2, 2008. REUTERS/Morteza Nikoubazl

He said the United States had “pretty clear” evidence that Iran was still training Shi’ite “special groups.”

He also said U.S. forces in Iraq continued to find many deadly armor-piercing munitions which the U.S. military says come from Iran, but he could not tell whether Iran had slowed the flow of those weapons.

Adm. William Fallon, the top U.S. commander for the Middle East, said the United States expected Iraqi leaders to convey to Ahmadinejad “the necessity of stopping this lethal flow of equipment”.

“We are working with our commanders to try to cut off this Iranian influence,” Fallon told the U.S. Senate Committee on Armed Services.