Erdogan tried to respond to an emotional 25-minute defense of Israeli military operations in Gaza by President Shimon Peres, but when after about a minute he was told he could not speak as it was time for dinner he walked out of the prestigious conference.
"Don't interrupt me. You are not allowing me to speak," he told the moderator, adding: "I will not come to Davos again."
He was given a hero's welcome when he returned to Turkey from Switzerland.
"The act of the Turkish prime minister reflects expectations of all Turkish people, the nations of the region and the entire world. We appreciate it. He behaved exactly how he should have behaved in that situation," Ahmadinejad told journalists.
The president of Iran again accused the Israeli government of committing war crimes in Gaza and declared that no aim could justify the killing of Palestinian civilians.
In Tehran on Saturday a group of protesters rallied outside the Turkish Embassy in support of Erdogan's actions. They chanted anti-Israeli and anti-American slogans, and some schoolchildren in the crowd carried flowers.
The new U.S. envoy to the Middle East, George Mitchell, is due to meet Erdogan in Turkey on Sunday. The Turkish prime minister said he was angry at not being allowed to speak, rather than at Israel or Peres, while the Israeli president said he did not expect Turkish-Israeli relations to be affected.
Israel's recent military operation in Gaza killed some 1,300 Palestinians. Up to 50,000 people were also left homeless in the enclave of 1.5 million. Israel's casualties in the conflict were put at 13, including 10 military personnel.