Iran's supreme leader Ayatollah Ali Khameni told the visiting Iraqi prime minister in talks Wednesday that the way to end instability in Iraq was for U.S. forces to withdraw, Iran's state-run television reported.

Nouri al-Maliki was making his first visit to Iran since he came to office in May, looking to a close ally of his Shiite-led government for help in calming the violence tearing apart Iraq and in developing Iraq's troubled oil industry.

In the latest sign of increasing cooperation, the two countries have reached a deal for developing joint oil fields that straddle their borders, and eventually Iraq will send crude to refineries in Iran for processing, Iraq's Oil Ministry said Wednesday.

Iran is also helping Iraq in its chronic shortages of petroleum products. Under a deal reached last month, Iraq will sell crude to its neighbor, which in return will sell back kerosene, and an Iranian-Turkish company will deliver gasoline from Turkey to Iraq across Iranian territory, Iraqi Oil Ministry spokesman Assem Jihad told The Associated Press.

The deals and al-Maliki's visit reflect the steadily strengthening ties between the U.S.-backed Iraqi government and Iran, a bitter enemy of the United States.

Al-Maliki's reception has been a warm one in Iran, where he spent part of his yearslong exile from Iraq during Saddam Hussein's rule. Khamenei — who holds the final word in all political matters in Iran — said Iran considers it an "obligation" to support Iraq's post-Saddam government.

But Khamenei made clear Iran wants to see U.S. troops leave Iraq, which he blamed in part for the turmoil plaguing the country.

"Part of (Iraq's) sufferings have been due to the actions of the former regime and part is due to the presence of occupiers in Iraq," Khamenei told al-Maliki, according to the Iranian state news agency.

"We hope a day will come when the Iraqi people reach the stage they deserve and that, by cutting the hands of the foreigners, its wealth will come to serve the Iraqi people," Khamenei said.

CountryWatch: Iraq | Iran

While welcoming Saddam's ouster, Iran has sharply opposed the American military presence in Iraq, leery of having U.S. troops on its doorstep.

However, Iran has benefited greatly from Saddam's fall, which eliminated one of its greatest enemies and paved the way for the rise to power of Iraq's Shiite Muslim majority, along with Shiite political parties with close ties to Iran's leadership.

The United States has repeatedly accused Tehran of interfering in Iraqi politics, harboring Al Qaeda fugitives and allowing insurgents to cross the porous 1,000-mile border. Iran denies the claims, but has not ruled out the possibility that some infiltrators might have crossed its border illegally.

In his visit, al-Maliki — who met President Mahmoud Ahmadinejad on Tuesday — asked Iran to take tougher measures to stop Al Qaeda militants from entering Iraq, according to Iraqi officials.

"Expansion of relations with friends and neighbors are the top priorities of Iraq's foreign policy," al-Maliki told Khamenei, according to Iranian state-run television.

The television also quoted al-Maliki as saying that instability was the biggest challenge for the Iraq government which he blamed mainly on supporters of Saddam.

Al-Maliki also met Ali Larijani, Iran's top nuclear negotiator and thanked Iran for hosting Iraqi leaders opposed to Saddam's rule.

"Iraq is Iran's natural ally," state-run television quoted Larijani as telling al-Maliki.

Despite its huge oil reserves, Iraq has been suffering under shortages of fuel products because of the damage to the industry from insurgent attacks and the turmoil in the country. It has also turned to Syria and other countries for supplies.

Jihad, from the Iraqi Oil Ministry, said the two countries had agreed to form commissions to define the reserves in joint oil fields that lie on both sides of their border. They agreed in principle as well to lay a pipeline to deliver crude from the Iraqi side of the joint fields to Iran for refining, he said.

Click here to visit FOXNews.com's Mideast Center.