CAIRO (AP) -- President Mahmoud Ahmadinejad's visit to Cairo on Tuesday, the first by an Iranian leader in more than three decades, highlights efforts by Egypt's Islamist leader to thaw long frigid ties between the two regional heavyweights.
Although the official welcome was warm, there was unscripted discord from Sunni protesters angry over Iran's support for the regime of Syrian President Bashar Assad, as well as decades of sectarian animosity between Shiite-led Iran and the region's Sunni majority.
At one point, Ahmadinejad was forced to flee an ancient mosque in downtown Cairo after a Syrian protester took off his shoes and threw them at him.
Later, anti-Iranian protesters raised their shoes up while blocking the main gates to Al-Azhar, the Sunni world's most prestigious religious institution, where Egypt's most prominent cleric chided Ahmadinejad for interfering in the affairs of Sunni nations.
The protests illustrate the limits to how far and how quickly Egypt's Islamist President Mohammed Morsi can go in reaching out to Iran: His Sunni allies at home view mainly Shiite Iran as a bitter rival, and Cairo can't afford to alienate Washington and Gulf Arab states who seek to isolate Tehran.
The three-day visit, centered around an Islamic summit, was an attempt by Morsi to strike an independent foreign policy and reassert Egypt's historic regional leadership role following the ouster of Hosni Mubarak, a close U.S. ally who shared Washington's deep suspicions of Tehran. Such a visit by an Iranian leader would have been unthinkable under Mubarak.
Morsi gave Ahmadinejad a red-carpet welcome on the tarmac at Cairo airport, shaking his hand, hugging and exchanging a kiss on each check.
The two leaders then sat down for a 20-minute talk that focused on the civil war in Syria, security officials said, speaking on condition of anonymity because they were not authorized to brief the media. Iran is Damascus' closest regional ally, while Egypt is among those that have called on Assad to step down.
Still, the chasm inherited from 34 years of bitter relations and the rift between overwhelmingly Sunni Egypt and Iran's Shiite leadership were on display.
Sunni-Shiite tensions dominated talks between Ahmadinejad and Egypt's most prominent cleric, Sheik Ahmed el-Tayeb, who upbraided the Iranian leader on a string of issues and warned against Iranian interference in Gulf nations, particularly Bahrain, where the ruling Sunni minority has faced protests by the Shiite majority.
El-Tayeb said attempts to spread Shiite Islam in mainly Sunni Arab nations were unacceptable and called for a halt to bloodshed in Syria, where Tehran's ally Assad has been battling rebels, according to a statement by Al-Azhar about the meeting.
The Sunni cleric also demanded that Ahmadinejad speak out against insults hurled at the first caliphs who succeeded the Prophet Muhammad and other figures close to the prophet in the 7th century. Those figures are widely resented among Shiites because they are seen as having pushed aside Ali, the prophet's son-in-law, who Shiites consider his rightful successor. The dispute over succession is at the root of the centuries-old split between Islam's Shiite and Sunni sects.
The meeting was "tense," acknowledged an aide to the sheik, Hussein al-Shafie, speaking at a news conference with Ahmadinejad that el-Tayeb did not attend.
Earlier, a Syrian man was arrested by police after he hurled his shoes at the Iranian leader outside the ancient al-Hussein mosque in downtown Cairo, according to security officials, who spoke on condition of anonymity because they were not authorized to speak to the media.
Ahmadinejad's visit came nearly six months after another historic first: a trip by Morsi to Tehran, where disdain for Egypt led the ruling regime to name one of its streets after the ringleader of the assassination team that gunned down President Anwar Sadat in 1981.
Egypt was once closely allied to Iran's former ruling shah. The two countries severed relations after the 1979 Islamic Revolution brought a clerical rule to power in Iran and Egypt offered refuge to the deposed shah. Ahmadinejad's visit to Al-Azhar brought him not far from a grandiose Cairo mosque where the shah -- despised by Iran's clerical rulers -- is buried.
Relations further deteriorated after Egypt's peace treaty with Israel.
"For the first time, we are witnessing breaking of ice between the two countries," said political analyst Rafaat Sayed Ahmed.
Ultraconservative Islamists known as Salafis, who view Morsi as too pragmatic and compromising but ally with him in the face of secular opposition, see Iran as Sunni Islam's greatest enemy. Salafi clerics often rail against Shiites and Iran in their sermons.
On Tuesday, Egypt's hard-line Daawa Salafiya, which is the foundation of the main Salafi political party Al-Nour, released a statement calling on Morsi to confront Ahmadinejad on Tehran's support for the Syrian regime and make clear that "Egypt is committed to the protection of all Sunni nations."
Egypt-Iran diplomatic overtures have raised concerns among Sunni Gulf nations, who are keeping a close eye on the Iranian leader's visit. The Gulf states accuse Iran of supporting Shiite minorities in the Gulf and harbor concerns about Tehran's disputed nuclear program.
Gulf countries, especially the United Arab Emirates, have made little effort to hide their enmity to the new Egyptian government out of fear the Islamists will export Egypt's revolution to their countries. The UAE has cracked down on Egyptian expatriates for links to Morsi's fundamentalist Muslim Brotherhood and has given refuge to former Egyptian regime members.
Morsi and the Brotherhood have sought to ease Gulf concerns, stressing that the security of the Gulf nations -- which Egypt has relied upon for financial aid to help prop up its faltering economy -- is directly linked to Cairo's own.
Foreign Minister Mohammed Amr Kamel reiterated that on Tuesday, saying "Egypt's relationship with Iran will never come at the expense of Gulf nations."
Morsi's government has presented the moves to improve ties as a policy of greater independence from the United States. He may also have geopolitical considerations: Gulf powerhouses Saudi Arabia and the United Arab Emirates are cool to Morsi's Muslim Brotherhood and his rule, and several experts said Morsi wants to keep the option of ties with Iran open as an alternative.
"Now relations with Gulf Countries are not that good. You need to make some balance and to play with all the cards you have," Egypt's former ambassador to Syria, Mahmoud Shukri, told The Associated Press.
Still, he and others said they don't expect normal relations to be restored between the two countries. "This phase is to open channels and have dialogue," Shukri said.
Morsi is also reluctant to alienate the United States, whose help Egypt is hoping for in rescuing its faltering economy, or to hurt ties with Israel, with which his government has maintained cooperation despite the Brotherhood's deep enmity to the Jewish state.
"I don't see that Egypt will make a decision separate from the course of its relationship with the U.S. and Israel, for whom Iran is now the main issue," said Mohammed Abbas Nagi, an Egyptian expert on Iran.
The Syria issue is also a complication. While Iran staunchly backs Assad's bloody suppression of the revolt, Cairo is home to the offices of the main Syrian opposition council, in which the Brotherhood's Syrian branch has a strong presence.
"The thorny issue here is Syria," said Ahmed, the political analyst. "Egypt can play a role when it stops talking about the downfall of the Syria regime, and take a step forward to host talks between the regime and the opposition."
Egypt's leader has spearheaded an "Islamic quartet" of nations to try to resolve the Syrian crisis. The grouping includes Iran, as well as Turkey and Saudi Arabia, which are two of the most vocal critics of the Syrian president.
Associated Press writer Aya Batrawy and Amir Makar contributed to this report.