TEHRAN (AFP) - Iranian supreme leader Ayatollah Ali Khamenei on Monday warned Iraq's visiting prime minister against signing an agreement with the United States keeping foreign troops in the country beyond 2008. The continued presence of US troops was Iraq's "fundamental problem," Khamenei told Prime Minister Nuri al-Maliki, expressing confidence that Iran's western neighbour would dash the "dreams" of the United States. The meeting - on the final day of Maliki's third visit to Tehran as prime minister - came amid alarm in Iran over the mooted Status of Forces Agreement (SOFA) pact between Baghdad and Washington. "The most fundamental problem of Iraq is the presence of the foreign forces," Khamenei told Maliki in comments reported by state television. "We are certain that the Iraqi people will pass the difficult circumstances and reach the status they deserve. For sure, the American dreams will not materialise." Washington and Baghdad are in negotiations aimed at signing the deal by the end of July to cover the presence of foreign troops beyond 2008 when the current UN mandate expires. Iraqi media reports have said the United States is seeking to keep as many as 50 bases indefinitely - suggestions that have alarmed Washington's arch enemy Iran. US officials have denied having such plans. Supporters of radical Iraqi Shia cleric Moqtada al-Sadr - said to be studying in Iran - have opposed the pact and Maliki has toughened his position since reaching an agreement in principle with US President George W. Bush last November. "The fact that a foreign element wants to interfere in the affairs of Iraq and dominate the country progressively is the main problem for the development and wellbeing of the Iraqis," Khamenei said. Television pictures showed the Shia Iraqi premier wearing a white shirt, without the necktie he had been wearing until now during his visit. Ties are still frowned on in the Islamic republic as a sign of Western imperialism. He thanked Iran for its "ceaseless" support of Iraq, state television said. Maliki had on Sunday sought to reassure Iran over the planned security pact, vowing Iraq would never be used as a platform to attack the Islamic republic. "We will not allow Iraq to become a platform for harming the security of Iran and neighbours," he said after meeting Foreign Minister Manouchehr Mottaki. Iran's concern about the deal comes amid renewed tensions over its nuclear drive, which the United States fears is aimed at making atomic weapons, a charge vehemently rejected by Tehran. The United States has never ruled out a strike against Iranian nuclear facilities while Israel has also been warning there may be no alternative to military action. Iran and Shia-majority Iraq waged a war between 1980 and 1988 in which around one million people died but ties have warmed considerably since the overthrow of Saddam Hussein's Sunni-dominated regime in 2003. Some observers had expected Maliki to use the talks to raise US allegations of Iranian interference in Iraqi affairs, a charge vehemently denied by predominantly Shia Iran. The United States has accused Iran of shipping in tank-busting munitions for attacks on US troops, training Shia militants inside Iran for operations in Iraq and supplying rockets for attacks in central Baghdad. However no mention of such allegations was carried in the official Iranian reports of the visit.