Hamas has known better days.

It is now ready to consider what it rejected for so long: setting up a joint administration of the Rafah crossing with the Palestinian Authority, the same authority it kicked out in 2007 when it took over the Gaza Strip.

Hamas has since repeatedly turned down calls to let the PA return as stipulated in the agreements concluded with Israel and the European Union.

However, beggars can’t be choosers, and Hamas hopes that such a move would placate the Egyptian Army and induce it to open the crossing more often. It would bring sorely needed relief to the population of Gaza, now openly grumbling against the organization. But there is no question of letting the European inspectors come back, since Hamas considers the agreements null and void.

Hamas, an offshoot of the Muslim Brotherhood set up in 1987, had placed great hopes in the then newly elected Egyptian president Mohamed Morsi, the candidate of the Muslim Brothers. It confidently expected the Rafah crossing would henceforth let people and goods flow in both directions; it also counted on the support of the new regime against Israel and against its rival, the Palestinian Authority.

It did not happen. Morsi, busy tightening his control on all public institutions while trying to tackle the disastrous economic and social situation of the country, let the army deal with the growing threat of terror in the Sinai Peninsula.

The Egyptian Army, now engaged in an all-out war against jihadist terrorism in Sinai, knows Hamas only too well and has scores to settle.

During the Mubarak years Hamas grew close to Iran, which funded its activities and supplied it with arms through Sudan. Coached by the Revolutionary Guards, Hamas set up a vast network to run arms, missiles and explosives through the Egyptian mainland to the peninsula and then to Gaza via underground tunnels.

Needing local help, Hamas recruited Sinai Beduin disenchanted with a central regime that neglected and oppressed them. Hamas terrorists were caught in Sinai and sentenced to jail.

A number of jihadist organizations inspired by al-Qaida took advantage of the unsettled conditions to infiltrate the peninsula and set up their own cells, with the tacit consent of Hamas, which saw in them potential allies against Israel.

“Tawhid and Jihad,” the group responsible for the attacks in Sharm el-Sheikh and Taba, was the first Salafist organization established in the area. It was followed by a host of smaller movements.

Each of these would recruit its own Beduin and set up its own military and ideological infrastructure.

With the fall of Mubarak and the disintegration of the security apparatus in Sinai, seasoned terrorists from Iraq and other Arab countries joined the fray. The civil war in Syria and the closure of Hamas headquarters in Damascus dealt a near death blow to the Iranian-Sudanese route, badly hit by operations attributed to Israel.

The fall of Libya’s Muammar Gaddafi opened another way to Sinai. Hamas and jihadist organizations found a common ground to move weapons from the dictator’s arsenals through Sinai to Gaza via the tunnels. In fact, Hamas believed that jihadist groups bent on attacking Israel would provide camouflage for their own activities, and that Israel would refrain from retaliating in order not to violate Egyptian sovereignty.

Interestingly, this ultimately led to the opposite, with the Egyptian and the Israeli armies having a common interest in stopping terror.

During the interim military regime which followed the fall of Mubarak, the army demonstrated its incapacity to do something in Sinai. The pipeline supplying gas to Israel and Jordan was sabotaged 14 times; jihadist groups, moving with impunity, attacked road blocks set up by security forces as well as police stations.

Following Morsi’s election, the army did try to do something, but never got the green light for a large-scale operation. There are indications that the president intended to reach an agreement with Hamas and possibly with jihadist organizations and turn them against Israel.

Egyptians, however, were getting increasingly angry with Hamas, especially after it was revealed a year ago that members of Izzadin Kassam (the military wing of Hamas) had crossed into Sinai through the tunnels in January 2011 at the height of the demonstrations against Mubarak and, together with their Beduin allies, had driven to Cairo to lead concerted attacks on a number of jails.

Among the some 20,000 prisoners freed were Salafists from Sinai, Hamas terrorists such as Ayman Nofel and the head of the Hezbollah cell arrested in 2009.

In less than three hours the newly freed Hamas terrorists had reached Gaza; Hezbollah gunmen took the longer route home and reached Beirut four days later via Sudan.

It turned out that a number of Muslim Brothers had escaped at the same time. Prominent among them was one Mohamed Morsi, who is still considered an escaped felon.

Needless to say, Hamas and its media have been vocal in their condemnation of Morsi’s ouster. In fact, Mahmud Ezzat, a deputy of the (imprisoned) supreme guide of the Brotherhood, fled to Gaza and is said to be coordinating opposition from there.

The Egyptian Army, which has launched an unprecedented campaign against terror in Sinai, enjoys wide popular support. There is great anger against Hamas, accused of supporting both terrorists and the Muslim Brothers. The organization is suspected of having aided and abetted the terrorists who murdered in cold blood 16 soldiers near Rafah last year.

Hamas does its best to reject these accusations, and Musa Abu Marzuk, the movement’s No. 2, claims that “it would be illogical for Hamas, which depends on Egypt, to act against it.”

On the other hand, the Palestinian Authority is only too happy to pour fuel on the flames. While demanding that the Palestinian Presidential Guard be allowed to resume its rightful place at Rafah, it points out that Hamas media are rooting for the Brotherhood.

Israel, for its part, shows understanding for the needs of the Egyptian Army and does not protest its operations alongside the Gaza Strip, though they go beyond the terms of the military appendix of the peace treaty. So far both armies are united in their fight to eliminate terrorism from Sinai.

Hamas has been hit hard. The Brotherhood is down in Egypt and the country has turned against Hamas. The steady destruction of the tunnels combined with the 500-meters-wide security zone set up along the border are asphyxiating Gaza, where a new political movement calls for the toppling of Hamas.

It is not likely to happen anytime soon.

Some say the Egyptians will invade Gaza. This is not likely either.

As to the third option – a desperate Hamas will turn against Israel – that is even less likely. It should be noted that Israel has quietly increased the amount of goods it lets into the Gaza Strip, and is even allowing the import of cement and building materials.

The writer, a fellow of The Jerusalem Center for Public Affairs, is a former ambassador to Romania, Egypt and Sweden.

Please LIKE our Facebook page - it makes us stronger