GAZA, Palestinian Territory - A suicide bomber blew himself up in the southern Gaza Strip on Thursday, killing a Hamas militant who was trying to stop the attacker from crossing into Egypt, Hamas announced, blaming an Islamic State sympathizer for carrying out the unprecedented attack.

It marked the first time that Hamas, which has carried out dozens of suicide attacks over the years targeting Israelis, was itself struck in such an assault. The Hamas-run Interior Ministry said five other Hamas security forces and an accomplice of the bomber were wounded.

The ministry described the assailant and his colleague as “ideologically deviant” - a term Hamas uses to describe members of the Islamic State group and other extremists. There was no immediate claim of responsibility.

Hamas, an Islamic militant group that seeks Israel's destruction, has ruled Gaza with an iron fist since seizing control of the coastal area in 2007. Hamas has since clashed repeatedly with more radical groups, which have carried out their own attacks against Israel in part to undermine Hamas.

Hamas has sought to secure Gaza's borders in order to improve relations with neighbouring Egypt, which is battling an Islamic State affiliate in the neighbouring Sinai Peninsula. Hamas has largely observed a truce with Israel since a 2014 Gaza war.

The Hamas fighter who was killed had been tasked with preventing Palestinians from sneaking into Israel or Egypt. He was also a member of the group's armed wing, which to “fight the alien deviant ideology without concession.” After the attack, Hamas forces set up dozens of checkpoints in the area and began searching cars.

The family of the attacker issued a statement condemning what he did, offering condolences to the security officer's family and refusing to hold mourning observances.

Hamas wrested control of Gaza from forces loyal to Western-backed Palestinian President Mahmoud Abbas in 2007, confining his forces to parts of the West Bank.

Groups inspired by IS, al-Qaida and others have created a headache for Hamas in recent years, accusing it of being too soft on Israel and failing to fully impose Islamic law. Such groups have bombed internet cafes and music stores, and attacked Christians. Jihadis killed an Italian activist in Gaza in 2011.

Egypt and Israel imposed a blockade on Gaza after the Hamas takeover that crippled the local economy. In recent years, Egypt has cracked down on the once-vibrant tunnel trade along the border. With Gaza's economy in shambles, Hamas is eager to improve ties with Egypt and ease the blockade.

Hamas has denied Egyptian accusations that it supports Sinai militants, and in June it began building a 13-kilometre-long (eight-mile) buffer zone along the border. It also beefed up border security in co-ordination with Egyptian authorities.

On Thursday, Egypt opened the Rafah border crossing, Gaza's main outlet to the outside world, for a fourth day to allow the departure of Muslims embarking on the hajj pilgrimage to Mecca and Medina, in Saudi Arabia. For the first time since March, the crossing was also open for humanitarian cases.

As part of new arrangements between Hamas and Egypt, facilitated by former Gaza strongman Mohammed Dahlan, the Rafah crossing is expected to operate on a more regular basis next month.