The Iranian news agency, IRNA, said shots were fired into the air by a man with a pistol who was then seized by the crowd. The man later told his interrogators he had no plans to kill the President but wanted to spoil the celebrations.
Mr Rafsanjani, 59, appeared unruffled and, after a short break, called for calm and resumed his speech marking the return from exile in 1979 of the father of the Islamic state. 'Hashemi, Hashemi, you are the apple of our eyes,' chanted the crowd.
The President told Tehran Radio after the shooting: 'I ask you to inform the people somehow that there is no cause for concern at all and no one should worry. I first thought a light bulb had blown up, but when I heard several more . . . I came to the conclusion that it was not a light bulb, it was firing. In my opinion there is no cause for concern at all. It was an incident in the corner of the huge gathering in the mosque. The proceedings of the meeting were not interrupted.'
IRNA identified the gunman as a 26-year-old named Kourosh. It did not give his surname. The agency quoted a policeman as saying the man used a US-made small-calibre revolver. The officer reported that the man had said he did not 'plan to assassinate any specific person. Rather, he meant to terrorise the people and spoil the celebrations.'
Witnesses said four or five explosions were heard that could have come from a small-calibre pistol. They said the shots came from about 50 metres from the platform where Mr Rafsanjani stood. IRNA quoted a major in the police force, Reza Mohammad-Doust, as saying that a number of forged student, police and press cards were found on the arrested man.
Iran's Islamic leaders were the targets of several assassination attempts in the early days of the revolution, but no serious incidents have been reported in the past 10 years.
Mr Rafsanjani, who was shot in the stomach in 1981 by the anti-Khomeini Mujahedin Khalq group, said on resuming his speech: 'Our enemies have lost hope in conspiring against us. Their newest trick is to use the morale of the people as a weapon.' The crowd immediately denounced the Iraq-based Mujahedin - invariably blamed in Iran for any outbreaks of political violence.
Within hours of the shooting, an organisation known as the Free Officers of the Revolutionary Guards said in a communique faxed from Tehran that it was behind what it called the assassination attempt, writes Safa Haeri. 'The Free Officers of the Revolutionary Guards claim the terror of the great apostate Hashemi Rafsanjani, the close aide and assistant of the other traitor, Ali Khamenei, by our heroic brother corporal Jalil Norouzi of the Vali e Asr's 7th Division. Our brother was arrested after his heroic action by the regime's torturer. May Imam Ali save him.'
A year ago, a shadowy organisation calling itself the Babak Khorramdin said it had attacked Mr Rafsanjani's motorcade in Tehran.