"They are not successful in their fight against terrorists, because they are playing a double game. They themselves created this excuse of terrorism themselves, and now they say that they want to stop them. It is not possible.
"The fight against terrorism is not a military one it requires the work of intelligence, through respecting nations and to separate people from terrorists."
While on a three-day visit to assess a US and Nato troop increase in the country, Gates had said that Tehran is "double dealing" in Afghanistan by stating that they are a good neighbour to Kabul while providing "low level support" to the Taliban.
Gates was on the last day of his visit in Afghanistan when Ahmadinejad arrived on Wednesday.
Ahmadinejad and Karzai had met to talk about "bilateral relations between the two countries and expansion of economic relations between the two countries", Siamak Hirawi, Karzai's spokesman, said.
Al Jazeera's James Bays, in Kabul, said, that until the issue of the US arose, the news conference mostly concerned regional co-operation.
"The two sides [Afghanistan and Iran] share a very long border," he said.
"They are both concerned about the Taliban and [the illegal trade in] opium."
It is the first meeting between Karzai and Ahmadinejad since they were both re-elected in disputed elections in 2009.
The US military invaded Afghanistan in 2001 to remove the Taliban, who they accused of supporting al-Qaeda operatives, from power following the September 11, 2001, attacks on the US of the same year.
Washington's forces remain in Afghanistan in an attempt to quell Taliban and al-Qadea attacks against Karzai's government.