In 1996, Israel faced a critical election for prime minister. The conservative candidate, Benjamin Netanyahu, was the underdog. The heavy favorite for prime minister was Shimon Peres, the dovish incumbent and the leading advocate for a peace agreement with the Palestinians.
As the election approached, Hamas suicide bombers carried out several deadly attacks, killing more than 50 Israelis.
Professor Nathan Brown, a Middle East expert at George Washington University, said this had a powerful impact on Israeli voters.
"Suddenly Netanyahu's message, which was, 'we can't trust the peace process,' started making an awful lot more sense," said Brown.
Those Hamas attacks boosted Netanyahu at the polls.
"In a very narrow victory, he was elected prime minister. So there was kind of a symbiotic relationship between them," Brown added.
Setting the stage for the current war
After many twists and turns over the years, this tortured relationship is now playing out in the full-scale war in Gaza.
"Obviously, there is no love lost between Netanyahu and Hamas," said Khaled Elgindy with the Middle East Institute in Washington.
They may be sworn enemies, yet they also kind of need each other. On multiple occasions, the hardline policies of one have been used to the advantage of the other.
"Hamas became useful to Netanyahu as a way to ensure that a cohesive Palestinian leadership did not emerge, and therefore there couldn't be a Palestinian state," said Elgindy.
In turn, Hamas has never negotiated with Israel and benefits from Netanyahu's recurring security crackdowns against Palestinians, said Nathan Brown.
"When the peace process looks like it's viable, Hamas is in a bind" he said, noting that at various times Palestinians believed the talks could lead to a Palestinian state. But, he added, when the Israeli-Palestinian negotiations break down, Hamas then goes to the Palestinian people and says, "We told you so."
Poisoning the Hamas leader
In 1997, just a year after Netanyahu was first elected, he approved an attempt to kill Hamas leader Khalid Mishal, who was then in exile in neighboring Jordan.
Israeli agents poisoned Mishal — but he survived — and the plot was exposed.
Jordan's King Hussein was furious and said a peace treaty with Israel was at risk. Netanyahu's government was forced to send the antidote for the poison to Jordan to help Mishal recover. The Israeli leader also had to release Hamas' imprisoned spiritual leader, Sheik Ahmed Yassin.
"That incident set the kind of tone for the relations between Netanyahu and Hamas. And things have been complicated ever since," said Ghaith al-Omari at the Washington Institute for Near East Policy.
Al-Omari advised the Palestinian negotiating team back in the late 1990s and early 2000s, when serious talks were taking place. Hamas, he recalled, repeatedly undermined those talks.
"Every time we would make progress in negotiations, Hamas would blow up a bus or a cafe," he said.
There have been no serious negotiations for a long time. Hamas has controlled Gaza for 17 years, and Netanyahu has been Israel's prime minister for more than 13 of the past 15 years.
Hamas attacks, Israel 'mows the grass'
This period has followed a pattern. Hamas denounces Israel's tough restrictions on Gaza, and periodically steps up attacks.
Israel's military hits back, and has a term for this, says Khaled Elgindy.
"They call it 'mowing the grass,' because every now and again, you have to go in and sort of cut everything down to size," he said.
In recent years, Netanyahu made limited concessions toward Gaza.
Nearly 20,000 Palestinians were permitted to enter Israel to work. The wealthy Gulf nation of Qatar was allowed to send up to $30 million a month to Gaza. This approach was known as "quiet for quiet."
Ghaith al-Omari says this suited Netanyahu. It allowed Gaza to function at a minimal level. At the same time, the Israeli leader could still argue that it was impossible to negotiate with the Palestinians as long as Hamas ruled Gaza.
"While he wanted to keep Hamas weak, he had no problem keeping them in control of Gaza," he said. "Hamas understood this. And until Oct. 7th, they played the game."
Yet this game — which helped Netanyahu and Hamas stay in power — was a chronically tense standoff, not a solution. It collapsed when Hamas unleashed its massive attack on Oct. 7.
Speaking to NPR in November, Netanyahu said Hamas must now be destroyed.
"Once you eliminate Hamas — and we have to eliminate Hamas — otherwise, this evil will spread," Netanyahu said. "But once we defeat Hamas, we have to make sure that there's no new Hamas, no resurgence of terrorism."
Khaled Elgindy said eliminating Hamas is unrealistic.
"At the end of the day, Israel is not going to destroy Hamas. But what sort of Hamas is left?" he said. "Will it be a Hamas that is more pragmatic and therefore inclined to moderate? Or will it be a more radicalized Hamas?"
Meanwhile, Netanyahu's political future is in jeopardy, said Ghaith al-Omari.
"The intelligence and security and military failure of Oct. 7 all happened under his watch," he said.
Still, he noted that the Israeli leader has been a remarkable political survivor.
"One of the jokes in Israel is that a cat has Netanyahu lives. It's impossible to write him off," al-Omari added.
For now, Netanyahu and Hamas are locked in their bloodiest battle yet, and neither is going down without a fight.
Greg Myre is an NPR national security correspondent who was based in Jerusalem from 2000-2007.