Jaafari met Supreme Leader Ayatollah Ali Khamenei, outgoing president Mohammed Khatami and president-elect Mahmoud Ahmadinejad for extensive talks that ranged from regional stability to military co-operation and energy and trade relations.

‘I hoped the visit would be a turning point in bilateral relations and compensate for the damage inflicted by Saddam,’ said Khatami after the meeting. In a move that will go some way to healing old wounds between the two countries, Jaafari apologised for the 1980-88 war, which he blamed entirely on the former Iraqi leader, who he said ‘was not a real representative of the Iraqi nation’.

US reaction to the warming relations has been cool, with deputy secretary of state Robert Zoellick saying: ‘Some aspects may be constructive, but be aware of what the other side wants.’

The US has sought constantly to pressurise the Iranian government over its nuclear programme, relations with Hezbollah and Palestinian militant groups and by accusing it of support for terrorism. Under the provisional government of Iyad Allawi, Baghdad also took a critical view of its neighbour, sometimes accusing it of meddling in Iraqi affairs.

Analysts believe any new relationship will be constrained by the Iraqi government’s reliance on US military and economic assistance. It may also encounter some opposition from other regional governments concerned that the emergence of a new Shia axis across the Shatt al-Arab will politicise Shia communities in their own countries.

But Iraq’s new government appears to view its relationship with Iran as a cornerstone of its foreign policy. The Supreme Council for Islamic Revolution in Iraq and the Patriotic Union of Kurdistan both have long relations with the Islamic republic, and their success in taking large shares of the vote have increased Iranian influence in Baghdad.

Iran is also preparing for a new political era, following last month’s election of Ahmadinejad, who takes office on 4 August. The president-elect is seen by many Iranians as something of a hardliner, and fought in the war as a special forces operative. But his role in relations will be partly restricted because foreign policy is determined by Khamenei and the Supreme National Security Council.

Jaafari was joined by 10 cabinet members on the visit, which led to agreements on future joint oil projects, electricity sharing and improved transport links. But the more significant talks were those centred on security.

Iraqi Defence Minister Saadoun al-Dulaimi earlier in July worked out an agreement for military co-operation with Iran, including shared work onborder security and counter-terrorism. Jaafari has also pledged to improve intelligence sharing between the two countries. With constant media speculation about US military action against Iran, the new agreements could ease some concerns in Tehran.