Khamenei said: "Supporting terrorist groups in Iraq and igniting insecurity ... will be very dangerous for America's agents and also the region."
Iraq "close to civil war"
Iraqis fear a new wave of sectarian blood-letting after a bombing on Thursday killed 202 people, the worst such attack since the US-led invasion in 2003.
Kofi Annan, the UN secretary general, said Iraq had been pushed closer to civil war and called for Iran and Syria to help.
"Iran will do its utmost to help establish security in Iraq"
Ayatollah Ali Khamenei, Iran's supreme leader
Send us your views
"Iran will do its utmost to help establish security in Iraq," said Khamenei, adding that Iran wanted a secure and developed neighbour.
Talabani has said that Iraq wants Iran's assistance.
Washington is facing growing calls to enter a dialogue with Iran to help end the violence.
The White House said the issue of talking to Iran and Syria about Iraq was likely to be raised at a meeting this week between George W Bush, the US president and Nuri al-Maliki, the Iraqi prime minister.
Bush said on Tuesday that conditions for the US to hold direct talks with Tehran had not changed. Washington still accuses Iran of seeking to develop nuclear weapons.
President Bush said during a press conference in Estonia: "As far as the United States goes, Iran knows how to get to the table with us, which is to do that which they said they would do, which is verifiably suspend their enrichment programme."
The US and other Western powers insist that Iran must suspend sensitive atomic work before negotiations start over a package of economic and political incentives offered by six world powers as a reward for such a move.
Iran has refused to stop and insists it does not seek atomic bombs but only wants nuclear technology to make electricity.