US troops must leave Iraq if security is to be restored, Iranian supreme leader Ayatollah Ali Khamenei has said during talks with the Iraqi president.
Iran is also concerned about mounting instability next door
He said the US was powerless to stop the unrest in Iraq, which was also bad for other countries in the region.
Iraqi President Jalal Talabani in turn called on Iran to stop backing Shia militias and support Iraq's government instead, Iraq's foreign minister said.
US President George W Bush has again ruled out removing US troops from Iraq.
"I am not going to pull our troops off the battlefield before the mission is complete," he told an audience in Latvia, where he is attending a Nato summit.
He earlier dismissed suggestions that the violence in Iraq amounted to a civil war, saying it was product of al-Qaeda's strategy to ignite sectarian strife in the country.
He also said the US would only open a dialogue with Iran if it showed it had suspended a uranium enrichment programme which can be used in weapons production.
While Washington may find it awkward seeing Iran as a growing powerbroker in Iraq, correspondents say, direct talks between Iran and Iraq to resolve the crisis may to some extent let the Bush administration off the hook.
'US must leave'
Ayatollah Khamenei said the US would not succeed in its aims in Iraq.
"The occupation of Iraq is not a morsel that the US can swallow," he said.
He said the US must leave Iraq if security is to be restored.
"The first step to resolve the instability in Iraq is the withdrawal of occupiers from this country and the transfer of security responsibilities to the popular Iraqi government," he reportedly said.
If asked by the Iraqi government, he said, Iran "won't spare any effort to contribute to stability and security in Iraq".
According to Iraqi Foreign Minister Hoshyar Zebari, President Talabani had urged his Iranian hosts to divert their aid to the government in Baghdad rather than to diverse groups, including Shia militias.
Mr Zebari told the BBC the Iraqi government message had been that the stakes were too high and Iran should do more to ensure the current administration did not fail.
He also said he detected some willingness on the part of the Iranians to address the issue of direct talks with the US over Iraq.
On Monday, Mr Talabani held talks with President Mahmoud Ahmadinejad, who said Iran was ready to do whatever it could to help Iraq.
Last year Mr Talabani, a Farsi speaker, became the first Iraqi head of state to visit Tehran in almost four decades.