Palestinian Hamas militants attend the funeral of their comrade killed by a suicide blast in Rafah, in the southern Gaza Strip, on Thursday. (Ibraheem Abu Mustafa/Reuters)

A suicide bomber killed a Hamas security guard in the Gaza Strip near the border with Egypt on Thursday, the first such attack to hit the Palestinian militant group.

Four other members of Hamas were wounded in the bombing at the Rafah crossing, said Eyad al-Bozom, a spokesman for Gaza’s Interior Ministry. He said the attacker was not affiliated with the Islamic State and was “ideologically deviant.”

Hamas, which has regularly used suicide bomb attacks against Israel, denies that Islamic State militants have a presence in Gaza, but it is struggling against an array of shadowy extremist groups. The Egyptian government has accused Hamas of allowing Islamic State militants from Egypt’s Sinai Peninsula to have a safe haven in Gaza. 

Israeli officials have also accused Hamas of cooperating with the Islamic State in the Sinai Peninsula.

Bozom said the bomber and another man were stopped by Hamas and refused to surrender before the one wearing a suicide belt detonated it. The second man was seriously injured in the attack.

Hamas was not the intended target for the bomber, who was bound for Egypt, Bozom said. Even so, the attack has the potential to increase tensions between rival factions in Gaza. 

The Ibn Tamiya Media Center, a Gaza-focused jihadist media group, released a statement saying that the attacker was “from us” and cursed Hamas for stopping him from carrying out an attack in Egypt. Hamas shot the bomber in the legs with “treacherous bullets,” the statement said.

The attack comes as Hamas has been forced to shift its allegiances, distancing itself from Islamic State-affiliated fighters in Sinai and bolstering ties with Egypt since the Palestinian Authority in the West Bank cut funding and electricity to Gaza to try to force Hamas to cede control.  

Earlier this year, Hamas agreed to a number of Egyptian demands, including better border security, in attempts to keep Gaza from being used as a refuge by Islamic State militants. In exchange, Egypt has sent fuel for Gaza’s power station and made assurances that it will open the border more regularly. The crossing was opened this week for the first time in three months to allow residents to use that route for pilgrimage to Mecca.

Morris reported from Jerusalem.