Updated

Iran's supreme leader publicly rebuked the president over his removal of a top official, a rare show of discontent with the hard-line Mahmoud Ahmadinejad by the country's most powerful figure.

The flap centered around control of a body that organizes the annual hajj pilgrimage to Mecca, traditionally part of responsibilities under supreme leader Ayatollah Ali Khamenei's vast powers. Khameini overturned the government's removal of the head of the organization.

The rebuke, issued in the press on Monday, comes at a time when Iranians are watching carefully for any sign as to whether Khamenei's support for Ahmadinejad is weakening as the president faces a tough battle for a second term in June 12 elections. Khameini's backing is important for any presidential candidate to win.

But given Iran's notoriously murky politics, it is hard to gauge where Khameini stands. The supreme leader has overruled Ahmadinejad at times in the past, only to later reaffirm his strong support for the president.

Some have seen other signs of weakening support. In March, the supreme leader said his stance is to support the president in power. But he also said that position was not connected to the elections and that he does not tell anyone who to vote for.

Ahmadinejad faces a strong challenge in the elections from reformists, who call for greater freedoms at home and better relations with the West. At the same time, Ahmadinejad's popularity has fallen among some in his conservative base, mainly because of the country's economic woes. His critics also accuse him of hurting Iran by his insistence on pursuing a nuclear program the West suspects is aimed at producing weapons and by denying the Holocaust.

Khamenei holds ultimate power in Iran, at the top of the Muslim clerical hierarchy above elected figures such as the president. If his support for Ahmadinejad is clear, then it would likely rally conservatives behind the president. If not, conservatives could take it as a signal to back an alternative candidate.

The dispute began last month when Ahmadinejad's government put the hajj committee under Iran's tourism authority. One of Ahmadinejad's vice presidents then dismissed the hajj organization chief, Mostafa Khaksar Qahroudi, and installed a replacement.

That brought a protest from the supreme leader's representative on hajj affairs, Ayatollah Mohammad Mohammadi Reishahri, who called the government's move illegal.

Khamenei issued a statement backing his representative and ordering Qahroudi be restored.

"Regarding the replacement in the Hajj and Pilgrimage Organization, the president was strongly notified that the annexation of this organization to the tourism committee is not appropriate," the government daily "Iran" quoted Khamenei as saying. He ordered that the "situation remain as it was before."

Perhaps more humiliating was that Khamenei addressed Reishahri and not the president in the notification.

It was undeniably a rebuke, and not the first.

In January 2008, Khamenei reversed a decision by Ahmadinejad and ordered him to implement a law supplying natural gas to remote villages. The order was seen as a stinging blow to the president, who was facing deep public anger over fuel shortages during a particularly cold winter.

Yet months later, Khamenei was unusually vocal in his backing for Ahmadinejad, calling him a brave leader who has stood up to the West over Iran's nuclear activities and praising his general performance.

He also said Ahmadinejad should run his government as if he would eventually serve a second term. Some saw that as Khamenei clearly backing his re-election, but others believed Khamenei was just intended to make sure the government worked hard.

Ahmadinejad came to power in 2005 elections with strong support from hard-liners. Khamenei never made his backing clear in that election, though many believe his son actively helped Ahmadinejad behind the scenes.