* Mortazavi detained after Ahmadinejad accused rival
* Row comes before presidential election in June
* Supreme leader calls for calm (Adds Mortazavi hearing details)
By Yeganeh Torbati
DUBAI, Feb 6 (Reuters) - A once-feared prosecutor at the centre of a row between two of Iran's most powerful figures was charged and freed from two days' detention on Wednesday, adding a new twist to their feud just months before the country's next presidential election.
Neither Monday's arrest nor the release of the former Tehran prosecutor, Saeed Mortazavi, who faces unspecified charges, have been accompanied by any public explanation from the authorities.
But Mortazavi was detained a day after his political ally President Mahmoud Ahmadinejad publicly accused the family of Parliament Speaker Ali Larijani of attempting to use their prominence for financial gain.
Larijani is a high-profile possible candidate to succeed Ahmadinejad, who is nearing the end of his second term and cannot run again straight away.
The timing of the detention suggested it was linked to the accusations and was a clear indication Ahmadinejad has lost the favour he once enjoyed from Iran's most powerful authority, Supreme Leader Ayatollah Ali Khamenei.
The Tehran prosecutor said Mortazavi was taken to court on Wednesday for a hearing of charges against him before being released, Mehr news agency reported. The report did not detail the charges but said investigations were continuing.
On Wednesday afternoon, Mortazavi resumed work as head of the social security office, Fars news agency reported. His appointment to the post last year outraged MPs after a parliamentary report accused him of being linked to the deaths in custody of three protesters in 2009 when Tehran prosecutor.
The squabbling between members of Iran's ruling elite has intensified despite repeated calls from Khamenei, the final arbiter on all matters in Iran, for officials to avoid airing their disagreements in public ahead of the vote in June.
The supreme leader is in direct charge of nuclear policy, but analysts say greater unity after the election may aid talks over a programme Western leaders say appears to be moving towards a weapons capability and Tehran says is purely peaceful.
Fars reported on Tuesday evening that judiciary chief Sadeq Larijani, the parliament speaker's brother, held a meeting with Khamenei after Mortazavi was detained. It did not elaborate.
Ultimately Mortazavi's arrest was a key sign of the discord in Tehran's corridors of power and his release was intended to restore calm, say analysts.
"It seems Iran's supreme leader is trying to contain the situation by ensuring that the tensions between Larijani and Ahmadinejad do not escalate any further," said Meir Javedanfar, a lecturer on Iranian politics at the Interdisciplinary Center at Herzliya, Israel.
"The most important goal of the supreme leader is stability before the upcoming presidential election."
Khamenei has not commented on Mortazavi's arrest or Ahmadinejad's accusations against the Larijanis, and analysts say he is unlikely to publicly involve himself in the recriminations.
Ahmadinejad, in Egypt on Wednesday for an Islamic summit, has been under increasing pressure from hardline factions.
His critics in parliament accuse the government of adopting policies that have worsened economic problems caused by Western sanctions over the nuclear programme.
In November, parliament called off plans to summon Ahmadinejad for questioning for what would have been only the second time after Khamenei called for greater unity among officials.
On Tuesday evening, Khamenei's foreign policy advisor Ali Akbar Velayati suggested in a speech that a candidate selected from Iran's conservative "principlist" faction could avoid the strife that has marked Ahmadinejad's second term.
Velayati is part of a three-man committee tasked with uniting parliament's principlists - hardline conservatives loyal to Khamenei and hostile to Ahmadinejad - around a single candidate to minimise chances of the virulent political divisions being carried into the election.
"If principlists are divided in the elections and the presidency is not in the hands of principlists in the future, we will have a tragedy," Velayati said.
"From these three people one person will be introduced as a candidate, so we can finish the job in the first round (of voting)," said the former foreign minister and possible presidential candidate, Mehr news agency reported.
"We hope ... we can in the future have a government that is responsive to the demands of the supreme leader and the people." (Additional reporting by Marcus George; editing by William Maclean and Philippa Fletcher)