Egyptian security immediately arrested the man.
You can just barely make out the man throwing the shoe on the left side of the video below (mark 0:13), later shown in slow motion.
As you may remember, a protester famously hurled his shoe at former President George W. Bush during a visit to Iraq.
"Around the Arab world, if you want to escalate a situation, by saying for example 'I'm going to thump you,' the BBC's Martin Asser wrote at the time, "Add the words 'with a shoe' and you're adding serious insult to the threat of possible injury."
Ahmadinejad, who recently announced that he's "ready" for a trip to space, was in Egypt for an Islamic summit.