Ismail Haniyeh, a top leader of Hamas, was assassinated Wednesday by an explosive device covertly smuggled into the Tehran, Iran, guesthouse where he was staying, according to seven Middle Eastern officials, including two Iranians, and a U.S. official.

The bomb had been hidden about two months ago in the guesthouse, according to five of the Middle Eastern officials. The guesthouse is run and protected by Iran’s Revolutionary Guard and is part of a large compound, known as Neshat, in an upscale neighborhood of northern Tehran.

Haniyeh was in Iran’s capital for the presidential inauguration. The bomb was detonated remotely, the five officials said, once it was confirmed that he was inside his room at the guesthouse. The blast also killed a bodyguard.

The explosion shook the building, shattered some windows and caused the partial collapse of an exterior wall, according to the two Iranian officials, members of the Revolutionary Guard briefed on the incident. Such damage was also evident in a photograph of the building shared with The New York Times.

Haniyeh, who had led Hamas’ political office in Qatar, had stayed at the guesthouse several times when visiting Tehran, according to the Middle Eastern officials. All of the officials spoke on the condition of anonymity.

Iranian officials and Hamas said Wednesday that Israel was responsible for the assassination, an assessment also reached by several U.S. officials who requested anonymity. The assassination threatened to unleash another wave of violence in the Middle East and upend the ongoing negotiations to end the war in the Gaza Strip. Haniyeh had been a top negotiator in the cease-fire talks.

Israel has not publicly acknowledged responsibility for the killing, but Israeli intelligence officials briefed the United States and other Western governments on the details of the operation in the immediate aftermath, according to the five Middle Eastern officials.

On Wednesday, Secretary of State Antony Blinken said the United States had received no advance knowledge of the assassination plot.

In the hours after the killing, speculation immediately focused on the possibility that Israel had killed Haniyeh with a missile strike.

That missile theory raised questions about how Israel might have been able to evade Iranian air defense systems again to execute such a brazen airstrike in the capital.

As it turns out, the assassins were able to exploit a different kind of gap in Iran’s defenses: a lapse in the security of a supposedly tightly guarded compound that allowed a bomb to be planted and to remain hidden for many weeks before it eventually would be triggered.

Such a breach, three Iranian officials said, was a catastrophic failure of intelligence and security for Iran and a tremendous embarrassment for the Revolutionary Guard, which uses the compound for retreats, secret meetings and housing prominent guests such as Haniyeh.

How the bomb was stashed in the guesthouse remained unclear. The Middle Eastern officials said the planning for the assassination took months and required extensive surveillance of the compound. The two Iranian officials who described the nature of the assassination said they did not know how or when the explosives were planted in the room.

Israel decided to carry out the assassination outside Qatar, where Haniyeh and other senior members of Hamas’ political leadership live. The Qatari government has been mediating the negotiations between Israel and Hamas.

The deadly blast early Wednesday shattered windows and collapsed a portion of the wall of the compound, photographs showed and the Iranian officials said. It appeared to do minimal damage beyond the building itself, as a missile probably would have done.

At around 2 a.m. local time, the device exploded, according to the Middle Eastern officials, including the Iranians. Startled building staff members, the officials said, ran to find the source of the tremendous noise, leading them to the room where Haniyeh was staying with a bodyguard.

A medical team declared that Haniyeh had died immediately. The team tried to revive the bodyguard, but he, too, was dead.