TEHRAN — Nearly three years after Iran’s reform-minded president was elected, the most reactionary voices in Iranian politics are losing ground to moderates buoyed by the sweeping nuclear deal with big powers, including the United States.

Though hard-liners still control the most powerful positions and institutions of the state, two national elections last week appeared to build on the slow but unmistakable evolution toward a more moderate political landscape — now and into the future.

Allies of President Hassan Rouhani made strong gains in parliamentary elections, controlling the entire 30-seat delegation representing the capital, Tehran, and carving out an influential minority bloc. At the same time, the two most radical clerics were ousted from the Assembly of Experts, a panel with the constitutional duty to select the nation’s next supreme leader, should that position become vacant.

The voting was seen as a referendum of sorts on the nuclear deal, and virtually every prominent critic of the pact was defeated.

The results also gave some weight to President Obama’s carefully couched hopes that the nuclear deal — which was heavily criticized by his American political adversaries — might introduce changes that could gradually bring Iran out of its confrontational posture with the West and, most pointedly, with the United States.

The election’s final results, which have not yet been made public, are not about to fundamentally alter Iran’s domestic or foreign policy, at least in the short term. But they do give momentum to a turn away from the most confrontational politics of the last president — Mahmoud Ahmadinejad — amid an electorate eager for Iran to emerge from decades of isolation.

“No more trivial debates, no more complaining of shaking hands with American officials, no more shouting and screaming from the Parliament seats,” said Farshad Ghorbanpour, an analyst with close ties to the Rouhani government. “The next Parliament will support the government; it will be reasonable and rational.”

While the hard-liners still remain firmly in control of the judiciary, the security forces and much of the economy, the success of the moderate, pragmatic and pro-government forces seemed to give Mr. Rouhani political currency to push a course of greater liberalization of the economy at home and accommodation abroad.

In the parliamentary elections, Mr. Rouhani and the moderates not only swept all seats in the capital but also appeared to run strongly in other urban areas.

The moderates also did well in the other election, for the 88-member Assembly of Experts, a panel that may be choosing the successor to Iran’s supreme leader, Ayatollah Ali Khamenei, who is 76 and has had health problems.

Ayatollah Akbar Hashemi Rafsanjani, a pragmatic and centrist former president, came in first in Tehran’s voting for the Assembly of Experts. He has long advocated stronger economic ties with the West and once suggested it was time to end the chant “Death to America” during Friday Prayer. Mr. Rouhani came in third place for a seat on the Assembly, and while a prominent conservative scholar, Mohammad Kashani, was second, two influential ayatollahs, spiritual leaders for the hard-liners, lost their seats.

By Monday afternoon, in the absence of official results, conclusions were being thrown around freely. State television reported Sunday that the hard-liners had won, and then reversed itself on Monday and gave the moderates the victory.

Image

A poster of the Iranian president, Hassan Rouhani, who led moderates to a sweep of parliamentary seats in Tehran.CreditVahid Salemi/Associated Press

Part of the problem was that so many candidates had been eliminated by a conservative vetting council that it was hard to know what faction some of the winners identified with. There are no political parties in Iran, and the candidates all run in loose coalitions along a relatively narrow political spectrum. There is no opposition to speak of, and the range of views was sharply curtailed when the reform movement was crushed after protesting what it called the fraudulent results of the 2009 election.

But it seemed clear that Iran’s ailing hard-line faction, having used every weapon in its arsenal against the moderate supporters of the Rouhani government, had come up short. In addition to the disqualification of thousands of candidates, street campaigning was kept to a minimum, and grass-roots activists were detained and intimidated.

When Election Day came, the president’s support base of middle-class Iranians turned out in big numbers, even though the overall turnout declined to 62 percent from 64 percent four years ago. A diverse group of Gucci lovers, student philosophers and family men carrying children wearing “Frozen” shirts, they came out for revenge against the hard-liners and appear to have exacted it.

Hard-liners, representatives of the sharper edges of Iran’s Islamic revolutionary ideology, have long had trouble attracting a large voter base. Iranian society has changed rapidly in 15 years, with the middle classes feeling more alienated by the harsh political talk against the United States, Western culture and any form of social relaxation.

Obtaining a strong minority in Parliament is not only Mr. Rouhani’s victory but also a result of a broader trend in which the Iranian political discourse is shifting away from a polarized universe of hard-liner versus reformist. Those supporting Mr. Rouhani prefer to call themselves pragmatists, centrists and moderates.

While the victory is significant, those expecting major social change in Iran will be proved wrong, both supporters of the government and hard-liners say. Those who made it into Parliament under the banner of reforms seem mostly to be cautious politicians. The original reformist leaders, who have pleaded for radical changes in law and ideology, are either in jail or prohibited from participating in the political process.

“They will quickly face division among themselves, since the supporters of the government is a mixed bag of individuals with different political backgrounds,” said Hamidreza Taraghi, a political analyst close to Iran’s leadership. “To write off the hard-liners would be a major mistake.”

Nevertheless, it is increasingly clear that Ayatollah Khamenei is supporting the moderate trend, at least in foreign policy and on economic issues. He was the main architect of the nuclear agreement. While he continues to warn against the United States, he has allowed continuing contacts between his foreign minister, Mohammad Javad Zarif, and Secretary of State John Kerry. He also welcomes and meets with European heads of state, most recently the president of Switzerland, Johann Schneider-Ammann, on Friday, urging the Swiss to invest in Iran.

In Tehran, the epicenter of middle-class culture, Mr. Rouhani has been criticized for his failure to deliver on any of his promises of more freedom and domestic political change. But fear of another four years of hard-liners in Parliament, combined with the successful nuclear deal and the lifting of the sanctions, prompted many to come out and vote for the president and his followers.

At a polling station in Shahrak-e Gharb, in western Tehran, families joined the older men who pass the days in a neighboring park for hours of waiting before casting their ballots. “I’m not into politics,” said Reza Sharji, 35, a graphic designer with a long hipster beard. “But I do know what I don’t want, that is more hard-liners.”

Social change is a highly delicate matter, and efforts there seem likely to meet continuing resistance. But economic changes and an opening to the world, a major focus of Mr. Rouhani’s government, might gain greater support. The shift toward the political middle gives Iran’s president the support of moderate conservatives, like the current head of the Parliament, Ali Larijani. To achieve such changes, they will have to overcome hard-line resistance to foreign investment and ownership of Iranian assets.

They are optimistic they can. “Now, such criticisms can be ignored,” said Mosayyeb Naemi, the editor in chief of a pro-government weekly. “The next Parliament will surely support the new economic policies.”

For those who came out in large numbers on Friday, the government victory, gnawing away at hard-liner power, was sweet, but their expectations remain low.

“We need better conditions for youths, women and minorities,” said Tahoura Ayati, 26, a translator of English literature. “I really hope for change, that is all I can say.”

A version of this article appears in print on , Section A, Page 1 of the New York edition with the headline: Iran Moderates Make Big Gains in 2 Elections. Order Reprints | Today’s Paper | Subscribe