Iran has arrested more than two dozen people, including senior intelligence officers, military officials and staff workers at a military-run guesthouse in Tehran, in response to a huge and humiliating security breach that enabled the assassination of a top leader of Hamas, according to two Iranians familiar with the investigation.

The high-level arrests came after the killing in an explosion early Wednesday of Ismail Haniyeh, who had led Hamas’s political office in Qatar and was visiting Tehran for the inauguration of Iran’s new president and staying at the guesthouse in northern Tehran, Iran’s capital.

The fervor of the response to the killing of Mr. Haniyeh underscores what a devastating security failure this was for Iran’s leadership, with the assassination occurring at a heavily guarded compound in the country’s capital within hours of the swearing-in ceremony of the country’s new president.

“The perception that Iran can neither protect its homeland nor its key allies could be fatal for the Iranian regime, because it basically signals to its foes that if they can’t topple the Islamic Republic, they can decapitate it,” said Ali Vaez, the Iran director for the International Crisis Group.

Officials in both the Middle East and in Iran itself have said the deadly blast was the result of a bomb that had been planted in Mr. Haniyeh’s room as long as two months before his arrival.