TEHRAN — In his almost three years as president of Iran, Mahmoud Ahmadinejad has been harshly criticized in the West. But he is increasingly drawing fire from Shiite clerics here, who accuse him of using religion to distract attention from his government’s failure to deliver on promises of prosperity and political freedoms.

In a news conference last week, the president lashed out at those who were “insulting and mocking” him about a Shiite belief that he said was based on Islamic teachings.

The tensions surround Imam Mahdi, the 12th imam in a direct bloodline from the Prophet Muhammad, who the Shiite faithful believe will one day emerge from 1,000 years in hiding to save mankind and bring justice to the world. Tens of thousands of pilgrims go each year to the Jamkaran mosque near Qum, about 75 miles south of Tehran, where they believe that the imam will appear.

President Ahmadinejad, who came to office in 2005 declaring his intention to “hasten the emergence” of Imam Mahdi, said in a speech broadcast nationally this month that Imam Mahdi supported the day-to-day workings of his government and was helping him in the face of international pressure.

That was too much for senior clerics, who contend that they alone are qualified to speak on the topic.

“Mr. Ahmadinejad’s remarks are common beliefs in Shiite Islam, but they were never brought up in politics and for political purposes by a noncleric,” said Farid Moddaressi, a religion reporter in Tehran. “Mr. Ahmadinejad’s views come from a religion which is defined by its clerics, but they believe that he is not a religious authority to make such remarks.”

Mr. Ahmadinejad, who has established a well-financed foundation to prepare the nation for the imam’s return, was stung by the criticism.

“To deny the help of the imam is very bad,” he said in his news conference. “It is very bad to say that the imam will not emerge for another few hundred years; who are you to say that?”

In the West, and especially in Israel, Mr. Ahmadinejad’s focus on Imam Mahdi’s return adds to the well-established alarm over his other beliefs and ambitions, the foremost being what experts say is his pursuit of a nuclear weapon. Given his complete opposition to a Jewish state and to the existence of Israel as well as his assertion that the Holocaust has still to be verified, his claim that the imam is directing his policies suggests to many abroad a toxic combination of mysticism, irrationalism and aggression that makes him a source of enormous danger.

Iranians, of course, take a milder view. They see Mr. Ahmadinejad as a deeply religious man, one who has maintained a modest way of life despite rising to the presidency.

“He is an absolute believer in the principles of religion and tries to implement them in his work,” said Mojtaba Samareh Hashemi, a senior adviser to the president. “When he talks about justice, he means a logical, philosophical justice that leads to religion.”

Many here say, however, that Mr. Ahmadinejad may not share all the conservative beliefs of Shiite clerics.

Mr. Ahmadinejad was once shown on television kissing the hand of his childhood teacher, a woman, even though it is deemed inappropriate for Muslims to touch members of the opposite sex to whom they are not married or otherwise related.

He challenged senior clerics in 2006 by defying a ban on women going to stadiums to watch men play soccer, but eventually he had to back down.

“He is religious, but he is not traditional,” said Saeed Leylaz, a political commentator in Tehran. “He kisses the hands of women, believes women should be allowed to go into stadiums, and he truly believes that the ground for the coming of Mahdi should be prepared.”

In his speech, which was made last month but not broadcast immediately, Mr. Ahmadinejad said Imam Mahdi was directing his government’s policies. He said he had the imam’s hidden support when he gave a speech at Columbia University in New York last September and was insulted by the president of the university.

With Imam Mahdi’s support, he said, 500 million people watched him on television. Mr. Ahmadinejad also said the United States had attacked Iraq because it had found out that “the divine hand” — apparently a reference to Imam Mahdi — was going to emerge there.

The escalation of the dispute in recent days seemed to suggest that Mr. Ahmadinejad was challenging Shiite clerics assumed to be the sole interpreters of the faith.

Several of Mr. Ahmadinejad’s critics said that by linking his government to Imam Mahdi, he was trying to deflect criticism of his economic policies, which have led to double-digit inflation.

A senior conservative cleric, Ayatollah Muhammad Reza Mahdavi Kani, warned him weeks ago not to talk about Imam Mahdi and said that even the founder of the 1979 Islamic Revolution, Ayatollah Ruhollah Khomeini, did not claim any links with the imam.

Another cleric, Mehdi Karroubi, who ran for president when Mr. Ahmadinejad was elected in 2005, warned that people could lose their faith in Imam Mahdi.

“People would say that if the current situation is his management before his emergence, what would happen after his emergence?” he said, referring to soaring food prices, the daily newspaper Etemad Melli quoted him as saying.

“We need to talk about realities,” said Mr. Karroubi, who is a former speaker of Parliament. “We should not link everything to religious and hidden issues.”

Copyright 2008 The New York Times Company