Iran leader denies claims of secret help for Taleban
Mr Ahmadinejad met Hamid Karzai, the Afghan president, at his heavily fortified presidential palace. After the meeting, he moved to the Iranian embassy under heavy guard before flying out of the country late in the afternoon.
While in Kabul, the Iranian delegation signed several agreements promising to help Afghanistan improve its capacity in building, agriculture and road construction.
The talks were overshadowed by accusations that Iran supplied weapons to Taleban insurgents, claims strongly denied by Mr Ahmadinejad.
"I doubt seriously if there is any truth in it," he told a press conference.
"With all our force, we support the political process in Afghanistan."
The claims have opened up a split between the US president George Bush and Mr Karzai. During a meeting at Camp David last week, Mr Karzai called Iran "a helper and a solution" to problems in Afghanistan, claiming it was a vital ally in the fight against terrorism and drugs.
Mr Bush countered this claim, saying he "would be very cautious about whether or not the Iranian influence there in Afghanistan is a positive force".
Despite Mr Karzai's claims that Mr Ahmadinejad's government is supporting reconstruction efforts in Afghanistan, intelligence sources in the country indicate they are also playing a hand at undermining NATO and US efforts to defeat the Taleban.
"It is clear to everyone that Iran is supporting the enemy of Afghanistan, the Taleban," Colonel Rahmatullah Safi, head of border police for western Afghanistan, which borders Iran, said earlier this month.