It was the first time Ahmadinejad has made such a call, publicly siding with hard-line politicians and clerics and commanders of the powerful Revolutionary Guard who have demanded in recent weeks that opposition leader Mir Hossein Mousavi and his top allies be arrested.
Ahmadinejad took an even tougher line than his top ally, Supreme Leader Ayatollah Ali Khamenei, who earlier this week said he saw no evidence that opposition leaders were tools of Iran's foreign enemies, a claim that hard-liners have made.
The differing stances suggest there are divisions within Iran's leadership over how far to take to heavy crackdown against the opposition since the disputed June 12 presidential election.
Hard-liners appear to be seeking to completely crush the pro-reform movement, calling for its political parties to be banned and leaders detained. Khamenei seems to be wary that going too far could fuel a backlash against the clerical leadership, which has already been weakened by the postelection crisis. Khamenei holds ultimate say in political issues in Iran, but he also needs to satisfy hard-liners and the Revolutionary Guard.
The government has already put on trial more than 100 senior figures and activists from the pro-reform opposition, accusing them of being part of a foreign-backed plot to overthrow the Islamic Republic through a "velvet revolution." Prosecutors allege that the wave of mass protests that erupted after the election claiming fraud were instigated by the opposition to spark that revolution.
But so far, despite hard-liners' calls, there has been no move to arrest the very top rung of the opposition — Mousavi and his allies Mahdi Karroubi and former President Mohammad Khatami. Doing so would be a major escalation in the confrontation.
In a harshly worded statement, Khatami lashed out at hard-liners, saying they were accused of "treason" in the public's eyes because of the fraudulent vote. He said the claims that the opposition protests were part of a foreign plot were a "very big mistake" and aimed to "justify violent, illegal and monopolistic behavior" by the government.
"The sacred Friday prayer podium has been given to those who ... call for the punishment of prominent figures ... while they are accused in the eyes of the public for committing treason themselves," he said, referring to hard-line clerics who have denounced the opposition during Tehran's main Friday prayers, one of the country's most potent political platforms.
Khatami said killing protesters and abusing detainees in custody has revealed the true nature of the ruling system in dealing with peaceful protests. "Is this the merciful Islamic image that defends morality and the people's basic rights?" he said in a statement posted on the Web late Thursday.
Hundreds of thousands joined street protests after the election, supporting Mousavi's claims of fraud, until security forces, the Revolutionary Guard and the pro-government Basij militia crushed the demonstrations with a crackdown in which hundreds were arrested. The opposition says at least 69 people were killed and that many of those detained were abused, tortured and even raped in prison.
The opposition has dismissed the month-old trial of opposition figures and activists as a "show trial" in which defendants were forced to make public confessions admitting to a plot.
Ahmadinejad's comments Friday came in a speech to thousands ahead of the weekly Friday prayers in Tehran. He said those on trial were "deceived" into participating in the alleged plot and that the leaders should be punished.
"These deceived, second-tier elements should be dealt with with Islamic mercy. Don't give immunity and protection to the main elements while punishing the deceived second-tier elements," he said.
"There must be a serious confrontation with the leaders and key elements who organized and provoked (the riots) and carried out the enemy's plan. They have to be dealt with seriously," he said, without directly naming the leaders.
Ahmadinejad also admitted for the first time that some detained protesters were abused in custody but also denied any government involvement, claiming instead that it was the work of Iran's enemies and the opposition.
"These actions that were carried out in custody ... were part of the enemy's scenario," he said. "Security, military and intelligence forces are free from these shameful acts."
Top police officials and a parliamentary probe has already confirmed that some prisoners were abused by their jailers. The government has been struggling to contain outrage among many Iranians over the accusations of abuse. The opposition says some detainees were tortured to death. Hard-liners have particularly been angered at Karroubi, who claims some prisoners were raped. The government says about 30 people were killed in the postelection crackdown.