Kofi Annan said that Ahmadinejad had told him on Sunday that Tehran would support the implementation of UN resolution 1701 that ended the fighting between Hezbollah and Israel in Lebanon, and was ready to negotiate over its nuclear programme.
Annan said Ahmadinejad had agreed in the talks in Tehran that Iran, which backs the Lebanese Shia group Hezbollah, would do everything to support the territorial integrity and independence of Lebanon.
Annan said: "Tehran will work together with us in a collective effort to reconstruct Lebanon."
State radio quoted Ahmadinejad as saying that Israel and its allies Britain and the US should compensate Lebanon for the "damages inflicted".
Tehran denies that it supplies weapons to Hezbollah fighters but many in the west and the Arab world believe Iran provided them with a large arsenal.
Qatar Airways, Qatar's national carrier, announced on Sunday that it will resume direct flights between Doha and Beirut "within the next 24 hours" despite the ongoing Israeli blockade on Lebanon.
"We have asked for authorisation from the Lebanese authorities and they have given it. Therefore flight QR 422 is going to go to Beirut," said a company spokeswoman.
"Qatar Airways will become the first international carrier to make a commercial flight into Beirut since the war ended," she added.
Annan (R) held talks with
Ahmadinejad on Sunday
Israel imposed an air and sea blockade on Lebanon at the outset of its 34-day conflict with Hezbollah on July 12. The blockade is being maintained despite United Nations Security Council Resolution 1701 calling for it to be lifted.
Annan's 10-day tour of the Middle East has been mainly aimed at implementing the UN resolution which halted the conflict that killed more than 1,000 Lebanese civilians, and 160 Israelis, mostly soldiers.
Resolution 1701 drew up the terms for the ceasefire, including expanding an existing UN peacekeeping force in Lebanon and calling for an arms embargo on Hezbollah.
Annan said his discussions about the resolution included measures to prevent the rearming of Hezbollah.
Meanwhile, Ahmadinejad told Annan that he was prepared to negotiate on Iran's nuclear programme but would not accept a suspension of uranium enrichment before talks, rejecting a key demand of the five permanent members of the UN Security Council plus Germany.
"Although we lost our confidence in the Europeans in the three years of negotiations that have gone by, we are nonetheless ready to negotiate under just conditions but they must act to obtain our confidence," state radio quoted Ahmadinejad as saying.
Annan expressed hope that the Islamic republic and international community would find a way to move forward in talks between EU foreign policy chief Javier Solana and Iran's top national security official Ali Larijani this week.
Iranian foreign ministry spokesman Hamid Reza Asefi said he expected the European Union to take a stand on its response to the offer aimed at ending the standoff, insisting negotiations were the only way out of the crisis.
The United States accuses Iran of seeking nuclear weapons, a charge denied by Tehran, which insists that its nuclear programme is solely aimed at providing civilian energy.
Annan also reiterated his displeasure over an exhibition in Tehran of cartoons on the Holocaust, drawing attention to the outrage among Muslims caused by the publication earlier this year of the Danish cartoons of Islam's Prophet Muhammad.
The comments came just hours after an Iranian foreign ministry spokesman said Iran plans to hold a conference this autumn questioning the extent of the Holocaust.
Annan, who has already visited Lebanon, Jordan, Israel and Syria, left Iran later Sunday for Qatar. He is also due to visit Saudi Arabia, Turkey and Egypt.