TEHRAN, Iran — In many other countries it would be a slam-dunk for the opposition: The president is increasingly unpopular, his economic policies are blamed for 30 percent annual inflation and his foreign policy has left the country more isolated than at any time in recent memory.

However, this is Iran, where things are never simple. President Mahmoud Ahmadinejad may be the subject of incessant grumbling and the butt of jokes zinging from cell phone to cell phone via text message. Yet with presidential elections six months away, he's still the man to beat.

The elections will be of intense interest to President-elect Barack Obama. Iran's alleged nuclear-weapons program, support for terrorist groups and influence in Iraq, Afghanistan and the Persian Gulf, are likely to make the Islamic Republic one of his main foreign policy challenges. Some observers have speculated that Obama may wait until after June before offering direct negotiations with Iran, in hopes that Ahmadinejad will be replaced by a more moderate figure.

Ahmadinejad's opponents, mostly reformers and some traditional conservatives, are struggling to capitalize on the president's woes and heal their own internal divisions.

"We're not sure we're going to have a consensus candidate," acknowledged Mostafa Tajzadeh, a deputy interior minister under former President Mohammad Khatami.

Tajzadeh spoke in an interview in the offices of a magazine published by the Islamic Iran Participation Front, a reformist party associated with Khatami. Days earlier, criticism of Ahmadinejad's economic policies dominated the party's annual meeting in Tehran.

Khatami, who served two terms as president from 1997 to 2005, has emerged as the opposition's best hope. An intense, behind-the-scenes campaign is under way to persuade him to run, according to Iranian political figures and analysts.

"Khatami looks like a savior to the people right now," said one analyst who requested anonymity because he feared retribution.

"We were critical of Khatami before," the analyst said, reflecting widespread disillusionment with the former president's failure to carry out reforms opposed by the country's conservative Shiite Muslim religious establishment. "Now we pray he returns."

Khatami, 65, said last week that he's considering running for his old job, but he hasn't decided.

Other potential candidates in the June election include Ahmadinejad, who has yet to announce that he'll seek a second four-year term; moderate cleric Mehdi Karroubi, who finished third in the 2005 presidential election; speaker of the parliament, Ali Larijani; and respected Tehran mayor Mohammad Baqer Ghalibaf, who holds the post Ahmadinejad once had.

Ahmadinejad appears to have the support of Iran's security forces, including the powerful Islamic Revolutionary Guard Corps, and of many poorer, rural Iranians, whom he's courted. Crucially, he also has tacit backing from Iran's supreme religious leader, Ayatollah Ali Khamenei — at least for now.

"The will of Ayatollah Khamenei is going to be a huge factor in determining who is Iran's next president," said Karim Sadjadpour, an associate at the Washington-based Carnegie Endowment for International Peace. "Though Khamenei publicly defends Ahmadinejad, he may well decide that the costs of having him serve a second term outweigh the benefits."

After the experience of the Bush administration, which criticized the entire electoral process and dismissed Khatami as ineffective — moves that Ahmadinejad used to his advantage — Obama may think twice about showing any preference.

Iranian elections are far from free and fair. Candidates' Islamic credentials are vetted by the Council of Guardians, a religious body dominated by Khamenei.

Iranian voters, however, have upset expectations in the recent past — including Khatami's victory in 1997 and Ahmadinejad's four years ago.

Ahmadinejad has lost the support of virtually every other major constituency in Iran. Tehran's powerful merchant class, the bazaaris, are angered by the rampant inflation and a proposed value-added tax that the government was forced to postpone in October after shopkeepers closed their doors in protest.

Young, upscale Tehranis express frustration with the dearth of economic opportunities and restrictions on social life, which had been loosened during Khatami's tenure.

Even Iran's conservative religious establishment, based in the holy city of Qom, is said to be alienated by what they perceive as Ahmadinejad's attempts to reduce their power while ruling on social issues. Two years ago, he lifted a ban on women attending men's soccer games, but backed down after a conservative backlash.

"I have no doubt ... that 70 percent of seminarians and clerics in Qom do not approve (of) and back Ahmadinejad," said one Iranian with close ties to senior religious figures. He, too, spoke on condition of anonymity for fear of retribution.

All of which has reformists pining for a unity candidate who can carry them to victory and begin tackling Iran's deep economic and social problems. To them, Khatami looks like the best bet.

"He's under pressure. Everybody's asking him to run," said Tajzadeh, of the pro-Khatami party. "If you would have asked me two or three months ago, I would have said (the chances of Khatami's running are) 20 percent. Now it's 50 percent and increasing."

Others aren't so sure.

Mohammad Kazam Anbarloui, the editor of the conservative Resalat daily newspaper, predicted that Ahmadinejad would win.

Iran's reformists, he said, "have big differences that they have not been able so far to resolve."