Tehran's ex-prosecutor and controversial ally of President Mahmoud Ahmadinejad has been released from Evin prison after spending almost two days in detention, Iranian media reported.

The reports on Wednesday did not elaborate on the circumstances of Saeed Mortazavi's release nor of his arrest on Monday night when he was sent to Evin, where many political prisoners and journalists have been imprisoned over years on his orders.

Mortazavi's detention, amid a brewing political fight between state branches, was criticised by Ahmadinejad as a "very ugly action".

Despite strong opposition from the parliament, Mortazavi is caretaker of Iran's wealthy social welfare organisation.

Before his post there, the 55-year-old was in charge of Iran's task force against smuggling.

But he is best known for his seven-year tenure as Tehran's prosecutor until August 2010, when he was suspended as a judge after a parliamentary probe found him responsible for sending anti-government protesters to Kahrizak, a detention centre south of Tehran.

Three protesters died in prison there, in the aftermath of the disputed 2009 presidential election that re-elected Ahmadinejad.

Source: Agencies