RIYADH - Saudi King Salman's meeting on Friday with Hamas leader Khaled Mashaal was part of an effort by Riyadh to shore up Arab unity in the face of a perceived threat from Iran that it believes has become more urgent since last week's nuclear deal.
Saudi Arabia, a conservative Sunni Muslim monarchy, has grown more aggressive this year in countering Shi'ite, revolutionary Iran across the region, believing its influence to be the main cause of instability and insecurity in Arab states.
Riyadh fears the agreement Tehran struck with six world powers to release it from sanctions in return for more intrusive inspections of its atomic facilities will free Iran to increase its support for Saudi Arabia's enemies in Arab countries.
"It's part of the grand strategy of countering Iranian influence. It's the main issue for Saudi Arabia and it's more urgent after the nuclear deal," said Mustafa Alani, an Iraqi analyst close to the Saudi Interior Ministry.
Since Salman became king in January, he has tried to build a Sunni coalition against Iran's regional allies, boosting support for rebels against Syria's President Bashar Assad and waging war against Yemen's Houthi militia.
The Saudis have for years regarded Hamas with intense suspicion because the Palestinian militant group is both a traditional ally of Iran and also an offshoot of the Muslim Brotherhood, a movement Riyadh has often seen as a threat.
Although the Brotherhood, like Saudi Arabia, is Sunni, Riyadh distrusts it because it combines a call to conservative religious values that might appeal to the kingdom's citizens with demands to replace dynastic rule with elections.
Salman's predecessor Abdullah put the Brotherhood on a list of terrorist organizations and backed Egypt's crackdown on the group, a policy that caused tension with Turkey and Qatar, its two main allies in fighting Iranian influence in Syria and Iraq.
Salman, while stopping short of befriending the Brotherhood, has worked to reduce tensions with the movement's own allies, strengthening Riyadh's ties with Ankara and Doha and reaching out to Islah, the Islamist group's offshoot in Yemen.CONFRONTATIONAL MOOD
"Saudi Arabia is in a confrontational mood against Iran and its in the business of gathering as many allies as possible. So if they reach out to Malaysia or reach out to Hamas, it's the same. It's to create as many allies as possible," said Jamal Khashoggi, head of al-Arab news channel, owned by a Saudi prince.
By building ties with Hamas, Riyadh might reduce tensions with Brotherhood allies and make it harder for Iran to present itself as the region's main defender of Palestinian resistance, and Saudi Arabia as covertly supporting Israel.
It also improves the chances Riyadh can help mediate a rapprochement between Hamas and the main Palestinian party, Fatah, potentially ending a split that has obstructed a push for statehood and led to recriminations around the region.
During last year's Gaza war between Israel and Hamas, Saudi Arabia waited three weeks before condemning the Jewish state's offensive and some newspapers close to the ruling family blamed the Palestinian group for provoking the fighting.
Anger over the plight of Palestinians and the failure of Arab governments to create a state has for decades driven much opposition to the region's rulers, particularly among Islamists who frame the Palestinian cause in terms of Muslim solidarity.
Meanwhile, by putting longstanding differences over political Islam on the backburner, Salman is strengthening ties with both Turkey, whose ruling AK Party is linked to the Brotherhood, and Qatar, which has given the group sanctuary.
Improved cooperation between the trio, the three countries most involved in supporting Syrian rebel groups, was credited earlier this year for opposition victories in Aleppo and the outskirts of Damascus.INSIDIOUS THREAT
Profound splits between the Middle East's Sunni states over political Islam linger, however, with both Egypt and the United Arab Emirates, core members of Saudi Arabia's coalition against the Houthis in Yemen, resolutely opposed to the Brotherhood.
Saudi Arabia's ruling princes themselves continue to look on the movement unfavorably. They recall how Riyadh offered sanctuary to its members during a 1960s purge in Egypt, and how they later backed a 1990s Islamist opposition movement against the ruling Al Saud.
Prince Nayef, the late veteran interior minister, elder full brother of King Salman and father of the current crown prince, once described the movement as "the source of all our problems in the Arab world".
While many of his living relatives still the see the group's secretive political activities and religious credentials as an insidious threat to their rule, it is Iran that they see posing the more immediate danger.
Riyadh hopes its new formula of tolerating the movement's activities outside Gulf countries, coupled with its support for Egypt's President Abdel Fattah el-Sisi, will keep both countries engaged in its wider struggle against Iran.
"The understanding with the Muslim Brotherhood now is that it will not be active inside Saudi Arabia or interfere in Gulf states. It's important that they understand these new rules of the game," said Alani.