The U.N. chief and Egypt's president delivered stinging speeches at a summit of developing nations in Iran on Thursday, damaging the host country's quest for global prestige and support for its nuclear programme and its policy on Syria.
The Iranians had to listen while Ban Ki-moon denounced them for calling for Israel's destruction and denying the Holocaust.
Nor did Mohamed Mursi, the first Egyptian leader to visit Iran since the 1979 Islamic revolution, mince his words as he urged Non-Aligned Movement (NAM) members to back Syrians trying to topple President Bashar al-Assad, Tehran's closest Arab ally.
The United States and Israel had frowned on the decisions by Ban and Mursi to attend the summit but they can only have been pleased with the discomfort the two men caused their hosts.
"I strongly reject threats by any member state to destroy another or outrageous attempts to deny historical facts such as the Holocaust," Ban said in his speech, without naming Iran.
"Claiming that Israel does not have the right to exist or describing it in racist terms is not only wrong but undermines the very principle we all have pledged to uphold," he added.
Iranian President Mahmoud Ahmadinejad has repeatedly denied the Holocaust and this month described Israel as a "cancerous tumour". In 2005 he was quoted as saying Israel should be "wiped off the map" - words that Persian language scholars say should have been rendered: "Israel must vanish from the page of time."
Iran has portrayed its hosting of the high-profile summit as proof that Western efforts to isolate it and punish it economically for its disputed nuclear programme have failed.
"Our motto is nuclear energy for all and nuclear weapons for none," Iran's Supreme Leader Ayatollah Ali Khamenei told the assembled heads of state, a day after Ban urged him to take action to prove Iran's nuclear work is peaceful.
The West suspects Iran is covertly seeking a nuclear weapons capability, an accusation Tehran denies.
In his speech, Khamenei criticised the U.N. Security Council as an illogical, unjust and defunct relic of the past used by the United States "to impose its bullying manner on the world".
"They (Americans) talk of human rights when what they mean is Western interests. They talk of democracy when what they have is military intervention in other countries," he declared.
Khamenei did not mention the conflict in Syria or Iran's staunch support for Assad, who is struggling to crush a 17-month uprising in which more than 18,000 people have been killed.
Mursi, a moderate Egyptian Islamist, said solidarity with the Syrian people "against an oppressive regime that has lost its legitimacy is an ethical duty" and a strategic necessity.
"We all have to announce our full solidarity with the struggle of those seeking freedom and justice in Syria, and translate this sympathy into a clear political vision that supports a peaceful transition to a democratic system of rule that reflects the demands of the Syrian people for freedom."
His words prompted Syrian delegates to leave the hall.
Syrian Foreign Minister Walid al-Moualem said the delegation withdrew "in rejection of the incitement in the speech to continue the shedding of Syrian blood", and returned after Mursi's address was over, Syrian state television reported.
Mursi said the bloodshed would only end if there were "effective interference from all of us". He appeared to be referring to diplomatic efforts, given that he has repeatedly ruled out any military intervention in Syria.
The NAM summit's final declaration is set to express deep concern about the violence in Syria and support for efforts by U.N.-Arab League envoy Lakhdar Brahimi to broker a resolution to the conflict, a delegate at the meeting told Reuters.
Mursi's blunt remarks on Syria suggested there would be no early restoration of Egyptian-Iranian diplomatic ties, which broke down after the Iranian revolution over Egypt's support for the overthrown Shah and over its peace agreement with Israel.
Shadi Hamid, of the Brookings Center in Doha, said Mursi, who has promised a "balanced" foreign policy, had signalled by going to Tehran that he would not be as closely aligned with the United States as his ousted predecessor Hosni Mubarak.
But his speech showed "he is not going to indulge the Iranians even when he sitting right next to them", Shadi said.
The emir of Qatar, whose country is believed to be arming Syrian rebels, called for a transfer of power in Syria through a political agreement, Qatar's state news agency reported.