(CNN) -- Iran's vital oil industry appears to be the latest front in a power struggle between President Mahmoud Ahmadinejad and Supreme Leader Ali Khamenei -- a fight that overseas analysts say the colorful president appears to be losing.
Ahmadinejad is trying to retain control of Iran's Oil Ministry despite a ruling by the country's top judicial body that he can't serve as its acting chief. It's the latest in a series of unusually public squabbles between Ahmadinejad and allies of Khamenei, the Islamic republic's clerical leader, in recent weeks.
Khamenei backed Ahmadinejad through the tumult that followed his hotly disputed 2009 re-election, urging Iranians to accept the results of the balloting when protesters in the streets declared it a fraud. He presided over a crackdown on the demonstrations, during which security forces were unleashed on crowds and activists were prosecuted and jailed.
But elements throughout the government have moved to check Ahmadinejad's efforts to replace top officials and have gone after the president's closest advisers, U.S. analyst Alireza Nader told CNN.
"I think it's a symptom of the general dissatisfaction with President Ahmadinejad that his powers and movement are being curtailed by the various power centers in Iran," said Nader, an expert on Iranian politics at the RAND Corp., an American think tank.
The outspoken Ahmadinejad has long been a lightning rod for Iran's critics. But Haleh Esfandiari, director of Middle Eastern studies at the Woodrow Wilson International Center, said he may be left a "lame duck" after butting heads with Khamenei.
"I think Ahmadinejad underestimated the power of Khamenei, and he overestimated his own power," said Esfandiari, who was jailed for more than three months in 2007 during a visit to Iran. "You can step on anybody's toes, but not on his toe."
Top officials and media outlets close to Khamenei have mounted a campaign of criticism targeting Ahmadinejad since mid-April, when Ahmadinejad tried to fire Intelligence Minister Heidar Moslehi. When Khamenei vetoed the move, Ahmadinejad retreated from the public eye, skipping Cabinet meetings.
Esfandiari said Ahmadinejad appears to have violated one of Khamenei's cardinal principles for Iran's leadership: Settle your differences in private.
"Khamenei all along has been trying to give the impression that the ruling class speaks with one voice, that there is unanimity among them," she said.
In early May, Ahmadinejad publicly swore allegiance to Khamenei and stressed his dedication to the principle of Velayat-e-Faqih, or Guardianship of the Supreme Jurisprudence, which forms the bedrock of Iran's Shiite theocratic rule.
But on May 16, Ahmadinejad declared himself the caretaker head of the Oil Ministry as part of an attempt to consolidate Cabinet agencies. That would put him in direct control of the world's third-largest oil reserves, the bedrock of the country's economy. But the leaders of Iran's parliament protested, and the Guardian Council -- Iran's top judicial body, dominated by Khamenei's allies -- ruled last week that Ahmadinejad can't act as the caretaker minister.
Wednesday, the head of the parliament's Energy Commission blamed Ahmadinejad for an explosion and fire at Iran's flagship oil refinery at Abadan that injured six people. The blast occurred when Ahmadinejad was visiting to attend the inauguration of a new unit at the facility, lawmaker Hamid Reza Katouzian said in comments carried by the Mashregh news agency.
"Some of the refinery's managers have said that it happened because they hurried the process of completion of the project," Katouzian said. He said those hurt "were sacrificed because of certain disagreements and the unnecessary insistence to leave the Oil Ministry without a caretaker."
Meanwhile, Iranian news agencies reported that Ahmadinejad's palace prayer leader, Abbas Amirifar, faces charges of "sorcery" after producing a controversial film predicting the imminent return of the Mehdi, a messianic prediction that Ahmadinejad often refers to in his speeches. Public criticism also has been focused on his brother-in-law and chief of staff, Esfandiar Rahim Mashaei, whom Ahmadinejad appeared to have been grooming as a successor.
Some of Ahmadinejad's moves appeared calculated to remain influential beyond the end of his term in 2013, Nader said. But he said Ahmadinejad made "a critical mistake" by firing Moslehi without consulting the supreme leader, and by skipping Cabinet sessions after Khamenei reinstated him.
"It's pretty incredible how much power and influence he's lost in the last few weeks," Nader said, adding, "I think it shows that he's not as powerful and consequential as he and a lot of people would like to assume."
Nader and Esfandiari said Ahmadinejad is unlikely to be forced from office -- something Nader said would amount to an admission of a mistake by Khamenei.
"The best outcome for the president is to serve his term, keep relatively quiet, stop being provocative and making decisions on his own," Nader said.
And Esfandiari said Khamenei, who has ruled Iran since 1989, has made it clear to observers inside and outside Iran just who is in charge.
"This is just the beginning," she said. "This is a story that will be unfolding over the next six months or year or so."
CNN's Shirzad Bozorgmehr contributed to this report.