Rouhani, the most senior elected official in Iran, tweeted to congratulate Maryam Mirzakhani for becoming the first woman to win the Fields Medal, which is nicknamed the Nobel Prize for mathematics.
The 37-year-old, who now lives in the US, appears once in the image wearing a headscarf or hijab, and a second time without.
Wearing the hijab has been compulsory in Iran since the 1979 Revolution and the lack of it is punishable by imprisonment, lashes or fines.
The tweet was hailed as a major step forward for women's rights in Iran, following a call for fainter headscarfs, or even no headscarf at all, to be permitted.
Rouhani was elected in 2013 and has publicly stated that he favours a softer approach to Islamic dress. However, Iran's judiciary is headed by Iran's most powerful individual, its supreme leader Ali Khamenei, who Rouhani reports to.
The 65-year-old has been celebrated by most of the Western world for being more moderate than previous leaders, although others have questioned this view.
He has since spoken of his views that even if women do not wear headscarfs, they may still be "virtuous", for which is was criticised by more conservative Iranians.
Rouhani's English Twitter account has published controversial statements before.
In May this year, when a group of Iranian men were arrested in the country for creating a musical tribute video to the Pharrell Williams song Happy, Rouhani's account tweeted in support of them: "#Happiness is our people's right. We shouldn't be too hard on behaviors caused by joy."
The English language Twitter account is not managed by him personally but is run by his aides.