The Iranian president's domestic opponents reacted furiously after photos emerged of him giving Elena Frias de Chavez, 78, a consoling hug at last Friday's funeral in Caracas - at which he also kissed Mr Chavez's coffin.
"I say directly that he went too far with what he mentioned in his tribute" Mr Khatami said. "The president is well aware that such a tribute will provoke reactions in our religious institutes He could have sent a diplomatic message with no religious connotations."
Mohammad Taghi Rahbar, the Friday prayer leader of Iran's second city, Isfahan, told Mehr news agency that Mr Ahmadinejad had "lost control".
He added: "Shaking hands with a non-mahram (unrelated by family) woman, under any circumstances, whether young or old, is not allowed.
Hugging or expressing emotions is improper for the dignity of the president of a country like the Islamic Republic of Iran." Mohammad Dehghan, a member of the governing board of Iran's parliament, the Majles, said the episode exposed the true nature of the "deviant current", the term used by allies of Ayatollah Ali Khamenei, the supreme leader, to describe Mr Ahmadinejad and his allies.
Conservatives loyal to Ayatollah Khamenei accuse Mr Ahmadinejad's administration of seeking to dilute Iran's Islamic principles. They also suspect the president of plotting to install one of his lieutenants in power after his second presidential term ends in the summer.
Last week, Ayatollah Ahmad Khatami, a senior Iranian cleric close to Ayatollah Khamenei, criticised Mr Ahmadinejad for predicting in a written tribute that Mr Chavez, who died of cancer last week, would return along with Jesus Christ "on resurrection day".