The Sinai militant group that later pledged allegiance to the Islamic State has been at war with the Egyptian government since 2013, when the military ousted the country’s Islamist government.

The group has since become one of the Islamic State’s most effective local affiliates. It downed a Russian jetliner in 2015, killing 224 people, and appears to have been responsible for an attack on a Sufi mosque in north Sinai in November, killing 311 people in Egypt’s worst terrorist attack.

Hamas is essentially a Palestinian national movement whose main effort is directed against Israel. It has periodically cracked down on more extreme jihadists in Gaza — who are ideologically closer to the Islamic State and Al Qaeda — including in a recent wave of arrests as extremists fired rockets into Israel to protest President Trump’s Jerusalem move.

Islamic State sympathizers argue that those arrests served only Israel.

Salah Bardawil, a senior Hamas official, described the video as a “Zionist” production. Another senior Hamas official, Mahmoud al-Zahar, said the Islamic State’s Sinai branch “does not want there to be weapons in Hamas’s hands to resist the Israeli occupation.”

Generally, though, Hamas has remained tight-lipped about the video, not wanting to draw more attention to it. Families whose sons have joined the Islamic State are reluctant to talk about them for fear of repercussions from Hamas, which dominates the Palestinian coastal territory.

“There is an undeclared war between Hamas and Daesh,” said Mkhaimar Abusada, a political scientist at Al Azhar University in Gaza, using the Arabic acronym for the Islamic State. “These are guys who disassociated themselves from Hamas and joined Daesh because they disagreed with Hamas’s participation in the 2006 elections. They don’t like Hamas’s behavior as it doesn’t enforce Shariah” — Islamic law — “and there are aspects of corruption regarding its rule in Gaza.”

Ehud Yaari, an Israel-based fellow of the Washington Institute for Near Eastern Policy, said that in the past Hamas had provided the Islamic State’s Sinai branch with training and advanced weapons, and had allowed wounded fighters to come to Gaza for treatment. The recent shift, Mr. Yaari said, was “a typical story of Middle Eastern changing alliances.”