Iranian judicial officials have blocked President Mahmoud Ahmadinejad from visiting Evin prison in the capital, Tehran.
Mr Ahmadinejad had asked to visit soon after a close aide of his was imprisoned there while the president was in New York last month.
But a judicial official said the visit was not appropriate at a time when Iran faced pressing economic problems.
The refusal is seen as an indication of Mr Ahmadinejad's waning authority.
"As we are faced with special circumstances and the country's priorities are the economy and people's living conditions, all authorities should focus on solving key issues... visiting a prison is extraneous," chief prosecutor Gholam Hossein Mohseni Ejeie told Isna news agency.
"More than seven years of his presidency have passed, and no request was made during that time," he said.
Mr Ejeie indicated that Mr Ahmadinejad's desire to visit the prison was linked to "a person affiliated to (the government) in prison," apparently a reference to presidential press adviser Ali Akbar Javanfekr.
Mr Javanfekr was arrested for allegedly insulting Iranian leaders.
Iran's judiciary is controlled by conservative hard-liners close to the country's supreme leader, Ayatollah Ali Khamenei.
BBC Persian's Kasra Naji says the episode is another indication of the declining authority of the president just eight months before the end of his term.
Iran has been facing a currency crisis that officials there blame on speculators and international sanctions aimed at Iran's nuclear programme.
Many Iranians blame the problem on President Ahmadinejad's policies.