However the relationship is unsteady as the Palestinian group sees Tehran's patronage as liability after Arab Spring and Syrian uprising.
Hamas prime minister Haniyeh arrives in Tehran
Ismail Haniyeh, the Hamas prime minister in Gaza, received a warm welcome in Tehran yesterday and is due to speak at a rally today marking the anniversary of Iran's 1979 Islamic revolution.
But the smiles failed to paper over frictions between Hamas and Iran, its long-time patron, as the Palestinian movement moves into the orbit of the mainstream Arab world.
The shift began with last year's Arab Spring and accelerated when Hamas rejected Iran's demand that the group publicly side with the Syrian president, Bashar Al Assad, in his crackdown against a popular uprising.
Angered, Iran is said to have cut its funding of Hamas, estimated at several hundred million dollars a year, since last August. Undeterred, Khaled Meshaal, Hamas's leader-in-exile, recently quit his base in Damascus and may move his headquarters to Jordan, which has a peace treaty with Israel, or to Qatar.
Backing Hamas has enabled Tehran, a sworn enemy of Israel which Iranian leaders often denigrate as a "cancerous tumour", to foster an image of supporting the Palestinians while claiming Gulf countries ignore their plight.
"But in these times of isolation for the Iranian government, Tehran needs Hamas more than Hamas needs Iran," said Meir Javedanfar, an Iranian-born analyst in Israel. "Hamas looks at post-Mubarak Egypt and they look at Turkey and they see these as much more powerful players that can do more for them than an isolated Iran."
Ordinary Iranians sympathise with the suffering of Palestinians but resent their regime spending money on Hamas and Hizbollah while Iran's own economy is battered by mismanagement and international sanctions.
A common chant during anti-government demonstrations after President Mahmoud Ahmadinejad's disputed 2009 re-election was: "Neither Gaza nor Lebanon, my life is a sacrifice to Iran."
Mr Meshaal has said repeatedly that Hamas supported a negotiated peace with Israel based on 1967 borders. But it has not renounced the option to take up arms.
In December, Mr Haniyeh rejected a shift to non-violence, insisting armed struggle was "the strategic way to liberate the Palestinian land from the [Mediterranean] Sea to the [Jordan[ River".
The Palestinian movement is increasingly relying on political and financial support from Iran's western-backed rivals in the Gulf, particularly Qatar, which Mr Haniyeh visited along with Bahrain and Kuwait this week before arriving in Tehran.
Qatar this week brokered a breakthrough unity deal between Mr Meshaal and his long-time rival, Mahmoud Abbas, the western-backed Palestinian Authority president.
Hamas's intention seemingly is to give a chance to Mr Abbas's idea of popular resistance though non-violent mass protests of the sort that toppled the entrenched regimes in Tunisia and Egypt.
But to end its isolation and make it an essential partner in Middle East negotiations, one that Israel and the West can no longer afford to ostracise as a terrorist group, Hamas will have to loosen its ties with Iran.
Qatar asked Mr Haniyeh to cancel his three-day trip but he was keen not to snub Iran while Hamas weighs options offered by the region's fast-changing political landscape.
He is due to receive an honorary law degree from Tehran University tomorrow, Iran's Fars news agency reported.
Readers commenting on a Hamas website this week overwhelmingly urged Mr Haniyeh not to visit Iran because of Tehran's backing for Mr Al Assad.
Hamas's spiritual and political roots lie with the Muslim Brotherhood, which have scored recent election victories in Egypt, not with the Shiite radicalism of non-Arab Iran.
In Syria, Mr Al Assad and his Alawite minority, which has roots in Shia Islam, are on the verge of a civil war with Syria's Sunni majority and its Muslim Brotherhood leaders.
"Hamas saw Iran's silence when Assad was bombing Palestinian refugees in [the Syrian city of] Latakia [last August] and decided to shift its strategy towards having more credible sources of support within the region," Mr Javedanfar, the analyst, said.