CAIRO — King Salman of Saudi Arabia met Friday with top political leaders of the Palestinian militant group Hamas, in the most striking example yet of the new king’s willingness to work with Islamist organizations long considered foes.

Analysts with close ties to the Saudi royal family said the meeting appeared to reflect King Salman’s determination to rally as much of the Arab world as possible against Iran, the kingdom’s chief rival, at a time when the Saudis fear that Iran will emerge empowered by its deal with Western powers to lift economic sanctions in exchange for limits on its nuclear program.

The meeting was held in Mecca and included Khaled Meshal, Hamas’s political leader who lives in Qatar. It was a startling reversal from the approach of the previous king, Abdullah, who had led a campaign to roll back or eradicate the Muslim Brotherhood and its affiliates around the region. Hamas is both an offshoot of the Brotherhood and a client of Iran.

But the new king has signaled that he is even willing to work with Brotherhood-style Islamists in his efforts to counter Iran, and analysts suggested Salman might be attempting to pry Hamas away from Tehran.