Last Updated, 5:44 p.m. Mahmoud Ahmadinejad’s visit to Cairo, which started with an affectionate welcome on Tuesday from Egypt’s new Islamist president, turned less pleasant as the day wore on. First, Mr. Ahmadinejad, the Iranian president, was lectured by a senior Sunni Muslim cleric and then was nearly struck with a shoe by a man furious at Iran’s support for the Syrian government.

A correspondent for Turkey’s Anadolu Agency captured the unsuccessful shoe attack on video and reported that the bearded man who tried to strike Mr. Ahmadinejad was a Syrian who shouted, “You killed our brothers!”

According to the Turkish news agency’s report, the man “was immediately detained” after hitting Mr. Ahmadinejad’s bodyguards with his shoe at Cairo’s al-Hussein mosque.

While striking someone with the sole of one’s shoe is a common sign of disrespect in Arab countries, the insult spread to other parts of the world after an Iraqi journalist, Muntader al-Zaidi, nearly hit President George W. Bush with both of his shoes at a news conference in Baghdad in 2008.

Earlier in the day, Mr. Ahmadinejad was apparently harangued during his meeting with Grand Sheik Ahmed al-Tayeb at Al-Azhar, Sunni Islam’s highest seat of learning. According to a statement released by Al-Azhar, Mr. Ahmadinejad was criticized for Iran’s role in what the cleric called the “spread of Shiism in Sunni lands.” The Sunni cleric also pressed the Shiite president to “not interfere in the affairs of Gulf states,” like Bahrain, where Iran is accused of lending support to protests against the ruling Sunni monarchy.

At a news conference after that meeting, Agence France-Press reported that Mr. Ahmadinejad “listened with noticeable unease” as another senior cleric complained about the disrespect shown to the Prophet Muhammad’s companions by “some Shiites.” Sunnis and Shiites disagree about whether the prophet’s companions or relatives were his rightful successors.