In the 26 years since the Iranian revolution, Ali Akbar Hashemi Rafsanjani has become not only a millionaire but the most conspicuous embodiment of a privileged political class far removed from the struggles of ordinary people.

Class has become a pivotal issue in Friday's vote for Iran's next president. And the gap between the country's political elite and everyone else has been sharpened by the surprise emergence of Rafsanjani's opponent, Mahmoud Ahmadinejad, the hard-line mayor of Tehran whose working-class background has endeared him to many Iranians and made the runoff election too close to call.

In Bagherabad, a sun-blasted working-class town 20 miles and a world away from the luxury high-rises of north Tehran, residents welcome the mayor's arrival on a political scene many have come to view with sullen anger.

"People talk about him a lot and say he's a good man to vote for," said Kobra Hassanzadeh, 50, behind the counter of a corner store that supports a family of five on $14 a day.

"They say he seems like us."

The number of other Iranians who see an ally in Ahmadinejad may decide Friday's vote, the first runoff in recent Iranian history. Campaign officials for Rafsanjani insist there is a limit to his rival's appeal. Of the 29 million votes split among seven candidates in the first round, they calculate that Ahmadinejad can count on no more than 11 million in the second round. If that's the case, they say, the mayor would prevail only if overall turnout dips toward 20 million.

"He has a mix of both religious conservative votes and rural and urban poor. That is a big base," said Nasser Hadian-Jazy, a political scientist who favors Rafsanjani.

Still, Hadian-Jazy said he believed Rafsanjani would win because reformers were worried about the alternative. "There's the fear factor," he said. "People will come out."

This week, it was Rafsanjani's campaign that looked to be running scared. The two-time former president bested Ahmadinejad by about 1 percentage point last week, then spent the brief runoff campaign promising to draw attention to social justice issues that his opponent had campaigned on heavily. On Thursday, a Rafsanjani supporter hastily unveiled a promise to put $11,000 in the pocket of every Iranian family by selling off state assets.

But it was the populist campaign of the scruffy, bearded Ahmadinejad that threw open a window on public discontent in Iran.

After last week's vote, an exit poll by the Ministry of Culture and Islamic Guidance found many voters were motivated by anger over the gap between rich and poor.

"Business is no good unless you enjoy a government rent or are the son of a cleric," said Faramarz Etemadi, 52, peddling black fabric for women's veils at a stall in Tehran's vast bazaar. "We had one shah, and now we have thousands."

Unemployment in Iran is officially at 10 percent but is widely thought to be twice as high. Inflation is at 16 percent. Per-capita income is $2,000.

"He's not one of the mullahs, so maybe he would work for people," Atieh Faramurzi, 48, a housewife in Tehran, said of Ahmadinejad.

Rafsanjani supporters said they found painful irony in the fact that their rival appealed to some voters bent on opposing the establishment. They say Ahmadinejad is a front for the conservative appointees at the top of Iran's byzantine constitutional structure who have thwarted the reformist agenda of Mohammad Khatami, the outgoing president. Khatami was twice swept into the presidency with more than 70 percent of the vote.

Critics say the mayor is a vehicle for others' goals. "He is like one of these disposable cups you use once and throw away," said Mohammad Atrianfar, a senior official in Rafsanjani's campaign.

"Of course," Atrianfar added, "the blame is not to be put on Ahmadinejad. The blame has to be put on the Iranian political structure and the Guardian Council."

The council is the most activist of three panels of self-appointed, mostly hard-line clerics whose authority outstrips that of any elected Iranian official. Last year, the Guardian Council used its power to bar all reformers from running for parliament. Critics say the clerics and their allies see in Ahmadinejad the opportunity to finally gain control of the executive branch and its ministries.

"Twenty-six years have passed since the revolution," Atrianfar said, "and they still haven't gotten their hands on the administration."

Ahmadinejad has denied being a front, but his career has deep roots in the murky power center that is Iran's military.

The son of a blacksmith, he was raised in the east Tehran neighborhood of Marmak, where from elementary school on he stood out as "the smartest student in east Tehran," said Hadian-Jazy, a former classmate. After the revolution, Ahmadinejad joined the Revolutionary Guard, serving in the eight-year war with Iraq as an engineer. He was also active in the basij, the state-sponsored militia that enforces rules against drinking and other behavior deemed un-Islamic.

In Tehran, Ahmadinejad's campaign headquarters brims with young men wearing long-sleeved black shirts, the uniform of the basij. Like officers in the Revolutionary Guard, those in charge chat with reporters but refuse to give their full names. Both groups are said to have turned out heavily for the mayor.

"We don't want extensions of freedom on a Western model. We want something of our own, something local," said Mohammad Shakiba, 19, a basij member, dressed in a business suit, who spoke in the courtyard of a mosque.

Ahmadinejad won the job of mayor two years ago after his conservative party prevailed in a local election with only a 12 percent turnout. Since then, his tenure has been distinguished by largess, as his office handed out money to community groups for religious observances and sharply increased the size of loans to newly married couples.

"This is unprecedented," said Hamid Bagheri, 23, who sells trinkets at an open-air kiosk in Bagherabad. "Nobody has helped us like that before."

Ahmadinejad promises to do the same on a national scale as president, subsidizing food and housing for the poor. His views are cryptic on relaxing social codes. The mayor, alone in the original field of presidential candidates, is cool toward the idea of re-establishing relations with the United States.

Rafsanjani, by contrast, has made the promise of negotiations with Washington a campaign centerpiece. He also promotes liberalizing Iran's government-dominated economy and keeping the government out of private lives, a key demand of many young Iranians, now a sizable majority in a nation where the voting age is 15.

Most important, supporters say, Rafsanjani has the stature to stand up to Ayatollah Ali Khamenei, who as supreme leader has ultimate authority in Iran and often sides with those who support the mayor. Atrianfar said Rafsanjani and Khamenei share a strategic interest in seeing Iran remain an Islamic republic but differ on the means. Khamenei is leery of establishing civil institutions and political parties, he said.

Diplomats and analysts said the election could also affect delicate negotiations over Iran's nuclear program, which the Bush administration and other governments fear could be used to develop weapons.

But after figuring significantly in the first round of campaigning, foreign affairs have been overtaken by economic concerns. And Rafsanjani's campaign style -- a tidal wave of posters, banners and bumper stickers, many featuring his name in English -- threatens to backfire by suggesting the candidate has money to burn.

"Who pays for this?" asked Mohammad Asadi, a retired civil servant. "If all this money he's spent is his money, it's a waste."

More controversial still are the text messages caroming among the relatively few who can afford the roughly $800 it costs for a cell phone account in Iran. Referring to Ahmadinejad as a "monkey" and "Afghanistan's Miss Universe," the mass messages brought a warning from the prosecutor of Iran's Revolutionary Court. They also illustrate class undercurrents running through both campaigns.

Wearing blue-tinted wraparound glasses with matching shirt and slacks, Vahid Tahmasbi stood out in an Ahmadinejad campaign office Tuesday. Explaining that he was a basij member and a flight attendant, he said he had volunteered to leaflet for the mayor.

Tahmasbi even persuaded several friends to volunteer. But when they showed up in fashionable clothes, the campaign basij members turned them away, Tahmasbi said. "They told them, 'You don't fit this place.' "

Mahmoud Ahmadinejad appeals to the working class. Ali Akbar Hashemi Rafsanjani is a millionaire.