Protesters defied dire warnings from top officials against demonstrating during the annual mass display of solidarity with the Palestinians that is one of the set pieces of the Islamic regime.
As Mr Ahmadinejad gave the keynote speech at Tehran University, renewing comments about Israel and the "myth" of the Holocaust that have sparked an international outcry, tens of thousands chanted "Death to the dictator" in nearby streets, witnesses said.
Shouting slogans in support of the hardliner's main challenger in the June 12 election, Mir Hossein Mousavi, the protesters gathered in major squares around the capital before joining the annual march to the university.
Hardline supporters of the regime among the more than 100,000 people who joined the Quds (Jerusalem) Day rally, mounted counter-demonstrations leading to repeated scuffles between the two sides, the witnesses said.
Riot police, armed with batons, beat protesters who were pelting them with stones in the central Haft-e Tir Square, witnesses said.
Police fired teargas to disperse the protesters, who were throwing stones and shouting: "Torture and rape are not effective any more", a witness said. The demonstrators were referring to opposition allegations of abuses against some of the more than 4000 activists and reformist politicians detained during the post-election disturbances.
Plain-clothes militiamen also battled the protesters in the same square.
"The plain-clothesmen on motorcycles rode into the crowd of opposition supporters as they were returning from the rally, detained several of them and beat them with batons," one witness said.
The demonstrators continued to chant "Death to the dictator" and "Allahu Akbar (God is greatest)" as they were being beaten, the witness added.
The opposition leader was forced to abandon his plans to take part in the rally after an angry crowd of hardliners shouting "Death to the hypocrite Mousavi" attacked his car, the official IRNA news agency said.
Former president Mohammad Khatami, a key supporter of Mr Mousavi whose 1997-2005 term of office saw a thaw in relations with the West, was also assaulted by hardliners before being rescued by riot police.
Mr Khatami's brother Mohammad Reza Khatami said the former president was "not hurt".
"Some people shouted slogans against him," the brother said. "He is home now. He is not hurt and he is fine."
There were also reports of clashes at Quds Day events in other major cities, as the unrest over the presidential election flared up again for the first time since July 19 in a sign of the seriousness of the challenge facing the regime.
Members of the Basij Islamic militia attacked and detained demonstrators in Tabriz in the northwest and in Isfahan south of the capital.
The wave of protests came despite a threat from the Revolutionary Guards Corps to crush any renewed attempt to contest the official election results giving Mr Ahmadinejad a landslide victory.
In his Quds Day address, the hardline President again described -- in his usual hysterically inaccurate and grossly insulting way -- the mass extermination of Jews during World War II as a "myth" and said Israel was on its way to collapse.
"They (Western powers) launched the myth of the Holocaust. They lied, they put on a show and then they support the Jews," he said to chants of "Death to Israel" from his supporters among the crowd.
"The pretext for establishing the Zionist regime is a lie ... a lie which relies on an unreliable claim, a mythical claim, and the occupation of Palestine has nothing to do with the Holocaust.
"This regime's days are numbered and it is on its way to collapse. This regime is dying."
Similar comments made by Mr Ahmadinejad shortly after his first election as president in 2005 sparked an international outcry and prompted Israeli Prime Minister Benjamin Netanyahu to describe Iran as an "existential threat" to the Jewish state.
Then Mr Ahmadinejad said Israel was "doomed to be wiped off the map".
The pro-reform camp claims Mr Mousavi was the rightful winner of the election and that the government faked the balloting in Mr Ahmadinejad's favour.
For a month after the June balloting, thousands of opposition supporters held street demonstrations against the vote fraud but were met with a heavy government crackdown.
Source: The Australian