​On Feb. 18, Mahmoud Karim , the first Egyptian ambassador to the Palestinian Authority in the 1990s, claimed that Egyptian media outlets were alleging Hamas involvement in Egyptian internal affairs in an attempt to conflate the movement with the Islamic State (IS) and al-Qaeda to distort Hamas' image and draw it into violent acts. However, it is in Egypt’s interest to achieve reconciliation with Hamas, as the latter is different from IS, Karim said. In one sign of possibly improving relations, Egypt unexpectedly opened the Rafah crossing for a week, June 13-19, and then for an additional three days, June 23-25.

Abdullah al-Ashaal, former Egyptian deputy foreign minister, told Al-Monitor, “These good indicators underline Egypt’s desire to improve its relations with Hamas, as the change in its position in favor of Hamas points to an official Egyptian wish to improve the living conditions in Gaza . This is especially the case after [Egyptian] efforts to exclude Hamas from the political arena failed, while many voices within the Egyptian regime have been calling for upholding Hamas’ role in the region.”

Hamas' foreign relations chief, Osama Hamdan, told Al-Monitor, “This decision is a step in the right direction toward the Palestinians and the beginning of a new relationship with Hamas. This is about strategic relations with regard to Egypt’s role in the Palestinian cause in light of Hamas’ nonintervention policy in Cairo’s affairs.”

This unexpected expression of gratitude followed a June 6 ruling by Egypt's Court of Urgent Matters overturning the Feb. 28 ruling designating Hamas a terrorist organization , a move that had exacerbated already heightened tensions between the two sides. Hamas spokesman Sami Abu Zahri welcomed the court’s decision, calling it the rectification of a mistake and confirmation of Cairo's regional role in the Palestinian issue. He said the ruling will have positive repercussions for relations between the two parties.

Relations between Hamas and Egypt have taken an unexpected gradual turn for the better, with Cairo expressing satisfaction with Hamas’ security approach toward Egypt, especially in the border areas. On June 25, Egyptian military officials praised Hamas for its role in Gaza, its policing of the smuggling tunnels at the border and preventing Salafi jihadists from infiltrating from and into Sinai.

Egypt’s change in attitude appears to be due, at least in part, to a Saudi role promoting rapprochement. During a June 16 meeting in Jeddah between Saudi Foreign Minister Adel al-Jubeir and his Egyptian counterpart, Sameh Shukri, the Saudis warned Cairo that it could lose its influence in Gaza, especially in light of the reconciliation between Hamas and Fatah that had taken place before the consensus government resigned, the quiet stretch between Israel and Hamas, as well as the good relations between Hamas and Saudi Arabia following the accession of King Salman bin Abdul-Aziz Al Saud in January.

Ahmed Youssef, former political adviser to Ismail Haniyeh and deputy chairman of Hamas’ political bureau, told Al-Monitor, “There are many positive indications in relations between Hamas and Egypt, suggesting that the upcoming period will see Egypt assuming a major role in the Palestinian issue, putting an end to the Egyptian media campaigns against Hamas and opening the Rafah crossing.”

Al-Monitor learned from a Hamas source who spoke on condition of anonymity, “Official meetings were held between the two sides [Hamas and Egypt]. The first one took place at Cairo [International] Airport on May 26 and included Moussa Abu Marzouk and Imad al-Alami, both members of Hamas’ political bureau on their way back to Gaza [from Turkey], and a number of Egyptian intelligence officers. The second meeting was held in early June in Qatar. The third meeting took place between Abu Marzouk and prominent Egyptian leaders on June 14.”

It appears that the three meetings in less than two weeks focused on three issues: putting an end to the negative media campaigns on both sides, securing the border between Gaza and Sinai and cooperating in the fight against the Islamic State (IS), which has been active in Egypt. Hamas agreed to the first two requests, but based on its policy of not interfering in countries' affairs, it was reluctant to join the battle Egyptian authorities have been waging against IS.

Despite Hamas' apparent disinclination to work with Cairo against IS, the Hamas-Egypt reconciliation comes at a time when IS has emerged as a common enemy. While the Egyptian army has been waging a relentless war on IS in Sinai, Hamas has been looking for the best, least costly way to contain its influence in Gaza.

The motives behind the rapprochement are linked in one way or another to the behind-the-scenes efforts of Hamas and Israel to come to an agreement on a truce. Mediators from Qatar, Turkey and the European Union are involved in the effort, while Cairo has remained on the sidelines, raising questions about Egypt’s future role in the Palestinian issue. On June 12, Hamas political bureau member Khalil al-Hayya declared that Egypt had stopped some time ago, at an unspecified date, following up on the cease-fire agreement signed between Israelis and Palestinians in August 2014, after the most recent war on Gaza.

Tensions and then complete estrangement have characterized the relationship between Egypt and Hamas since the overthrow of President Mohammed Morsi in July 2013 and the subsequent closure of the Rafah crossing and establishment of a buffer zone in the border area. Regardless, Hamas was keen to keep relations with Cairo at least hanging by a thread, no matter how thin, as the movement had become isolated in the region.

This helps explain Hamas’ mild reaction to a June 16 Egyptian court ruling against a number of the movement’s prisoners and martyrs. At the time, Salah Bardawil, a senior Hamas leader, said that the movement did not wish to further strain relations, which were seeing improvement, by commenting on the Egyptian ruling. With Egypt practically its only gateway to the outside world — the Rafah crossing remains the only outlet for Gaza's more than 1.8 million Palestinians — Hamas recognizes that it has no other choice than to engage with Egypt.