Hassan Khomeini, a grandson of Iran's Ayatollah Ruhollah Khomeini, speaks at the Interior Ministry in Tehran on Dec. 18. (TIMA/Reuters)

The power struggle in Tehran between moderates and hard-liners is heading toward a showdown in next month’s elections , which could shape the political balance in Iran for years to come.

The Feb. 26 elections will select 285 members of the Iranian parliament, the Majlis, and 88 members of the “Assembly of Experts,” which will choose the eventual successor to Supreme Leader Ayatollah Ali Khamenei.

“This is a fight for survival,” one Iranian told me Thursday. Since the Iranian revolution of 1979, he said, “we have never had such an election” in which the competing factions in Iran were so starkly opposed and the stakes were so high.

U.S. officials, who are carefully watching the preelection jockeying, expect that if the hard-liners don’t rig the outcome by excluding candidates, the elections will produce a “slight gain” for the moderate camp surrounding President Hassan Rouhani and “continued momentum” for his opening to the West, including the nuclear deal reached in July.

A political barometer closely watched by U.S. officials is the candidacy of Hassan Khomeini, the popular grandson of the ayatollah who embodied Iran’s revolution. He’s running for the Assembly of Experts as an independent but is seen as an influential supporter of Rouhani’s pragmatic policies.

Rumors swirled this week that Khomeini might not run, after he missed a religious examination in Qom. But the Iranian source, who knows Khomeini, insisted Thursday that “he has not withdrawn” from the race and that any effort by the hard-liners to force him out would backfire. More than 200 other clerical candidates for the Assembly of Experts had also skipped the exam, this Iranian source said.

Khomeini is a charismatic figure who for Iranians represents the legacy of the revolution and also the effort to adapt it to the 21st century. His Facebook page, which has more than 100,000 “likes,” posts a picture of him as a boy sitting next to his bearded grandfather, Ayatollah Ruhollah Khomeini.

The Iranian power struggle will intensify in coming weeks as the roster of candidates is screened by a group known as the Guardian Council, which vets their revolutionary credentials. The hard-liners are likely to try to prune the field, but the moderates have prepared by registering so many candidates for the Majlis — by one count, there are more than 12,000 people running — that a total purge would undermine the election’s credibility.

The dilemma for the supreme leader and the hard-liners around him is how to maintain their power without discrediting the political process. They have to balance public perceptions of legitimacy against their fear that the moderates will gain control of the parliament in addition to the presidency.

“If the Guardian Council permits a wide swath of candidates and there is no vote-rigging — two huge ifs — then candidates supportive of Rouhani’s pragmatic agenda should win overwhelmingly,” predicts Karim Sadjadpour of the Carnegie Endowment for International Peace. Indeed, another Iranian source estimates that 60 to 70 percent of the public supports Rouhani’s pragmatic approach. But Sadjadpour cautions that decisive power in Iran remains with the supreme leader, not elected officials.

Yet even the supreme leader must keep an eye on public opinion, as is shown by his recent decision on deployment of Iranian military forces in Syria. Those numbers were growing last year, and hard-liners wanted to send even more. But analysts say that after the Iranian death toll in Syria began rising sharply, the supreme leader ordered a withdrawal of some troops in the fall. The number today is said to be roughly 1,000, or about half what it was. Iraqi and Lebanese proxy forces have filled the gap.

The deepening political divide in Iran contrasts with what U.S. officials say has been a recent consolidation of power within the royal family in Saudi Arabia, Iran’s bitter rival across the Persian Gulf. A power struggle seemed to be developing in October between Crown Prince Mohammed bin Nayef and his headstrong, 30-year-old deputy, Prince Mohammed bin Salman.

But King Salman is said to have intervened personally recently to check the family rivalry. According to officials from a neighboring gulf country, tensions between the crown prince and his deputy have eased, with Mohammed bin Salman recognizing the need for more harmony within the House of Saud.

The confrontation this past week between Iran and Saudi Arabia was a reminder that 37 years after the Iranian revolution, the aftershocks are still rocking the Middle East. It’s intriguing that a leading voice of the moderation in next month’s elections is the grandson of the scowling ayatollah who set this upheaval in motion.

Read more from David Ignatius’s archive, follow him on Twitter or subscribe to his updates on Facebook.