STANFORD, Calif. — Although the Israeli and Iranian governments have been virtually at war with each other for decades, the two countries have much in common.

Both are home to some of the oldest civilizations on earth, and both are primarily non-Arab states in a mostly Arab region. In the 1950s, David Ben-Gurion’s Israel and Shah Mohammed Reza Pahlavi’s Iran were bastions of secular nationalism; the shah pushed authoritarian modernization, while Ben-Gurion advanced a form of nonreligious Zionism. Only after the 1979 Islamic revolution in Iran did radical Islam all but eclipse this secular brand of politics. It held on for much longer in Israel but is now under threat.

Both Iran and Israel are now entering potentially challenging new stages in their relations with the outside world, and particularly with the United States. Over the last seven years, United Nations Security Council resolutions have imposed sanctions on Iran with the aim of halting its nuclear program. For years, Iran’s former president Mahmoud Ahmadinejad railed against the “Great Satan.” But even if Iran’s supreme leader, Ayatollah Ali Khamenei, is still opposed to reforms, it appears that some officials inside Iran have finally realized that continued intransigence and bellicosity will beget only more sanctions and catastrophic economic consequences.

As the winds of change blow across Iran, secular democrats in Israel have been losing ground to religious and right-wing extremists who feel comfortable openly attacking the United States, Israel’s strongest ally. In recent months, Israel’s defense minister, Moshe Yaalon, called Secretary of State John Kerry “obsessive and messianic,” while Naftali Bennett, Israel’s economy minister, labeled Mr. Kerry a “mouthpiece” for anti-Semitic elements attempting to boycott Israel.