Mr. Madani, the deputy head of the Department of the Environment, a cabinet position, had been visiting Bangkok in March when a private photo taken five years ago in the United States showing him dancing was leaked on the internet. Iranian officials are supposed to adhere to strict laws that forbid dancing. After months of pressure and intimidation, Mr. Madani decided not to return to Iran and does not want to disclose his current location.

Image Kaveh Madani Credit... Imperial College London

“I feel things are not getting better but getting worse and affecting my beloved ones,” Mr. Madani wrote. “I say this with a broken but hopeful heart. I resign.”

He is the second associate of President Rouhani to resign in recent weeks. The mayor of Tehran, Mohammad Ali Najafi, resigned last month after criticism over his presence at a show where grade-school girls performed a traditional dance. He resigned citing health reasons.

The resignations are a sign of the increasing pressure being exerted by the hard-line judiciary, the news media and the Islamic Revolutionary Guards Corps on Mr. Rouhani and his faction of reformists and moderates after protests in December and economic upheaval in recent months.

President Trump has threatened to withdraw the United States from the 2015 nuclear agreement, a signature achievement of Mr. Rouhani’s that the Iranian president said would bring economic prosperity.