The scene in Lebanon on Tuesday and Wednesday was like something out of a bizarre James Bond movie - with pagers exploding simultaneously in the pockets of hundreds of Hezbollah fighters around the country in what appeared to be an ingenious Israeli operation that combined cyberwar with sabotage.

But Hezbollah gets to write the next chapter in this real-life thriller. And Israeli officials were preparing Tuesday night for retaliatory attacks that, if not contained, could trigger the all-out regional war U.S. officials have been trying to head off for nearly a year.

Israel didn’t take credit for the attacks, but it didn’t need to. Attacks of this sophistication and daring in Lebanon could not have been staged by any other nation. The video scenes of Hezbollah fighters blown to the floor by their own communications devices sent an unmistakable Israeli message to the Iranian-backed militia: We own you. We can penetrate every space in which you operate.

Biden administration officials were quick to distance themselves from the attacks in Lebanon, saying they had not been given any prior notice. For President Joe Biden and Vice President Kamala Harris, the timing couldn’t be worse: This sharp escalation and risk of a wider war comes less than two months before the presidential election - and it might detonate any chance of a Gaza cease-fire deal and the release of Israeli hostages.

U.S. officials were in contact with Iran through a back channel on Tuesday to convey that the United States did not have any role on the first attack. The administration’s sense, for now, is that Hezbollah is confused and panicked, and that it won’t make an immediate military response. If there is an attack, U.S. officials believe Israel can contain the damage.

Israel’s apparent decision to launch the attacks was probably driven by both political and operational factors. The U.S.-led cease-fire plan is stalled, and with it the hope of a diplomatic deal with Hezbollah to calm the border. And having developed the extraordinary ability to turn their adversary’s communications devices into bombs, Israel might have judged that this capability must be used before it could be discovered and the pagers disarmed.

Israel’s desire to strike Hezbollah harder reflects a broad view among Israelis that the country can’t afford what has become a prolonged war of attrition with Lebanese militia members. Though Israel has effectively neutered Hamas militarily in Gaza, Hezbollah has continued to expand its rocket attacks against northern Israel. More than 60,000 Israelis have been forced to evacuate their homes in the north, leaving behind what amount to ghost towns.

The ingenuity of the pager attack was Israel’s apparent penetration of Hezbollah’s secretive supply chain - which had distributed the exploding devices. The group’s leader, Hasan Nasrallah, had warned his operatives in a February speech to stop using cellphones, which had “become like everyone’s oxygen,” but which gave away the fighters’ positions and sometimes acted as Israeli spying devices.

Hezbollah rushed to protect its military network by providing members with special pagers that used a system that was harder to crack. The militia surely never imagined that Israeli operatives could penetrate their supply chain for the pagers. But that’s what appears to have happened, U.S. cyber experts told me. Hezbollah sent a telling message late Tuesday to its operatives: “Each one who received a new pager, throw it away,” according to a source quoted by The Post.

What caused the devices to first explode Tuesday and again on Wednesday? When the first attacks began to flood Beirut hospitals with what would be more than 2,800 casualties, several U.S. analysts told me they initially suspected that Israeli malware might have triggered explosions of lithium batteries in the pagers. But videos that captured several of the detonations make that theory unlikely. Lithium batteries get very hot before they explode - so hot that nobody would keep them long in their pockets. And the explosion was typically preceded by smoke and then fire, the videos appear to show.

What likely happened, U.S. sources told me, was that Israeli agents managed to get access to the pagers themselves before they were distributed and inserted small amounts of very powerful explosives. Malware inserted into the pagers’ operating systems likely created a cyber trigger, so that when the pagers received a call from a particular number - or some other signal - the explosives detonated, the sources said.

From a technical standpoint, it was a brilliant operation. The Hezbollah network has now lost its special internal communications system. And because it appears to have Hezbollah’s number, quite literally, Israel can send messages warning surviving operatives that they will be killed if they try to retaliate, one U.S. source noted.

Beyond its devastating effect on Hezbollah, the attack signals the beginning of a new and very dangerous era in cyberwarfare.