Former Iranian president Mohammad Khatami has received an honorary degree from St Andrew's University during a three-day trip to the UK.
Mr Khatami said "borderless friendship" would save the world
After being met with protests from some students and Iranian exiles, he delivered a lecture in which he talked of a "borderless friendship".
Opponents claim people were tortured, jailed and executed during Mr Khatami's presidency.
His visit has provoked fury from human rights organisations and politicians.
In his speech, Mr Khatami said the world was being threatened by all kinds of conflicts including religious confrontations.
He spoke of a letter written by Imam Ali, the great Imam of Muslims, in which he tells one of his friends people should be treated compassionately because "they either share the same religion with you or are created the same way as you".
"If someone does not share their religion with me, they are definitely respectable and entitled to receive compassion as human beings," Mr Khatami said.
"The call by our Imam is clear. He recommends not only tolerance but something beyond that which he refers to as profound compassion.
"One can live within the religious, geographical and political borders but they must extend love profusely.
"Borderless friendship will save the whole world."
After receiving his degree, he smiled and received rapturous applause from the audience.
He also opened the new Institute of Iranian Studies.
In an address, Professor Michael Bentley of the university's school of history said Mr Khatami had "taste and aptitude for ideas and a commitment to dialogue between cultures".
He added: "When universities honour people of other faiths, cultures and value systems they invite the criticism that they're lending their imprimatur to regimes or ideologies which are deemed unacceptable.
Mr Khatami was met by protesters at St Andrew's University
"That is understandable but it is also an error of judgment."
Prof Bentley added that Mr Khatami would not expect endorsement for each of his beliefs or for actions carried out in his name.
"What we can and should offer is acknowledgement of a courageous stand against insularity and our congratulation on real and persistent efforts to reach out and engage with nations of the West who often cleave to aspirations very different from his," he said.
Mr Khatami had been met by principal and vice-chancellor Dr Brian Laing and Dr Ali Ansari, the institute's director.
Dr Lang said: "St Andrews wants to recognise this man for his vision and his desire to change and for his wish to engage with the west.
"The degree denotes that the university is grasping his outstretched hand."
The visit comes at a time when international relations with Iran are strained over nuclear development.
St Andrews University students distanced themselves from plans by the National Union of Students to demonstrate against the visit.
Mr Khatami, who was president of his country from 1997 to 2005, is the most senior Iranian figure to visit the UK since the country's revolution in 1979.
Strong criticism has come from the Committee of Anglo-Iranian Lawyers.
Its president, Masoud Zabeti, told BBC Radio Scotland that Mr Khatami had committed crimes against the Iranian people.
"There are some who want to whitewash his crimes and pretend he is some sort of moderate.
"To put on Mr Khatami's shoulders all the ills of a regime which does have brutalities is to completely misread the political and historical situation," he said.
Scottish Conservative MEP Struan Stevenson described the decision to invite him as a "slur on Scotland".
The invitation was supported by Jack Straw when he was foreign secretary.
A university spokesman said that far from being a slur on Scotland, the visit reflected the international standing and status of the institution.