Story highlights This is the first visit to Egypt by an Iranian president in more than 30 years

Prosecutor's office: Four men are out on bail after allegedly throwing the shoes

Officials say the men are Salafis, who have accused Iran of financing Shiites

During a historic trip to Egypt, Iranian President Mahmoud Ahmadinejad was greeted by a group of men who hurled shoes at him -- a major insult in the Muslim world.

A video posted by the Anadolu news agency shows a smiling Ahmadinejad shaking hands with a crowd of supporters in Cairo late Tuesday when at least one man threw a shoe toward him. Other men also threw shoes at Ahmadinejad, the Egyptian public prosecutor's office said.

"You killed our brothers!" one of the assailants shouted, according to Anadolu. The agency said the man's shoe struck a security guard.

The men behind the attack were four Salafis, the prosecutor's office said.

Salafis follow the Sunni Muslim doctrine and oppose the idea of Shiite Muslims engaging in any political activity in Egypt. They have accused Iran of financing Shiites to spread the Shia doctrine in Egypt, which has a Sunni majority.

JUST WATCHED Peres: Iran is competing with Egypt Replay More Videos ... MUST WATCH Peres: Iran is competing with Egypt 00:59

The four men were released on bail for 500 Egyptian pounds ($75) each, the prosecutors' office said.

Ahmadinejad's visit to Egypt is the first by an Iranian president in more than 30 years.

He was in Cairo visiting the Grand Sheikh of Al Azhar, Ahmed el-Tayeb. The Al-Ahram news agency said Ahmadinejad also visited the historic Al-Hussein mosque.

The mosque was built in 1154 and it is named after the Prophet Mohammed's grandson, Hussein Ibn Ali. Shiites believe that the Fatimid, Egypt's Shiite rulers, buried his head there and built the mosque as a shrine for Hussein, the first Shiite martyr, who was killed and beheaded in the battle of Karbala in 680.