Among thousands who attended the prayers was Mir Hossein Mousavi, the defeated pro-reform presidential candidate.
It was Mousavi's first public appearance since the June 12 vote, which he says was rigged. The authorities deny any fraud.
The disputed election triggered widespread protests across the country, resulting in at least 20 deaths in clashes between protesters and security forces and government-backed militia.
Rafsanjani in his sermon broadcast live on radio urged people "not to contaminate the position and the sanctuary of Friday prayers by inappropriate] comments and slogans".
But pro-reform supporters interrupted Rafsanjani's sermon chanting slogans of "Freedom! Freedom!".
One caller to Persian radio station said the gate at Tehran University was closed, and people were being turned away.
People outside the university shouted "Death to the dictator" and tear gas was fired in response, witnesses said.
One eyewitness told Al Jazeera: "After continuous shouting by the protesters, the police fired teargas on them. Some were beaten."
"We are free, and based on our constitution, we are free to have peaceful demonstrations. It is not against the law. We are following and keeping to the law."
One witness told the Reuters news agency that at least 15 people had been detained during clashes outside the university.
Alireza Ronaghi, Al Jazeera's correspondent in Tehran, said: "Rafsanjani said we must preserve the Islamic nature of our government and without the people's votes and trust, the government cannot be Islamic.
"And that's the argument that Mir Hossein Mousavi and Mehdi Karroubi [another defeated presidential candidate] have been putting forth.
"He's trying to open a way for solving the standoff, and give a convincing option for those dissatisfied with the election outcome."
Mousavi, Ahmadinejad's main challenger, has refused to accept the electoral outcome.
But opposition demands for annulling the results have been rejected by the election authorities and Ahmadinejad, re-elected for a second term, on Thursday accused Western powers of interfering in last month's vote.
Ahmadinejad also criticised Rafsanjani over his support for Mousavi.
Rafsanjani is one of Iran's wealthiest and most powerful men, and one of only four Tehran clerics allowed to address the nation during the weekly Friday prayers.
Rafsanjani heads two of the regime's most powerful bodies: the Expediency Council, which settles disputes over laws between the parliament and the Guardian Council, and the Assembly of Experts – which has the power to appoint, supervise and in theory dismiss the Supreme Leader.
The election strained ties between Iran and Western nations, already at odds over Tehran's nuclear programme.
Gholamhossein Mohseni-Ejei, Iran's intelligence minister, told the Fars news agency: "The vigilant Iranian nation must be aware that tomorrow's sermon should not turn into an arena for undesirable scenes."