In February 1998, a bus bringing the mathematical elite of Tehran's Sharif University back from a competition in the western city of Ahwaz skidded out of control and crashed into a ravine.

Seven award-winning mathematicians and two drivers lost their lives in the crash. One of the survivors was Maryam Mirzakhani, who this week became the first woman – and also the first Iranian – to win the Fields medal, seen as the Nobel prize for mathematics.

The news prompted widespread celebration across Iran: President Hassan Rouhani even risked a backlash from hardliners by posting her picture without a hijab on Twitter. "Congrats to #MaryamMirzakhani on becoming the first ever woman to win the #FieldsMedal, making us Iranians very proud," Rouhani tweeted on Wednesday along with two pictures of Mirzakhani, one with a headscarf and the other without.

Under Iranian law, women are required to cover themselves from head to toe in public and those defying the ban risk arrest. In 2010, the prominent human rights lawyer Nasrin Sotoudeh was sentenced to six years in jail, but received an additional sentence of five days in jail for posting a video of herself without a hijab. Sotoudeh has since been released. Marzieh Vafamehr, an Iranian actress, was also sentenced to a year in prison and 90 lashes in 2011 for appearing in an Australian film with her head uncovered.

Negar Mortazavi, a social media activist based in Washington, said on Twitter that the president's move in sharing the photo of Mirzakhani was unprecedented. One Iranian, highlighting the controversy surrounding Rouhani's tweet, joked: "I congratulate Maryam Mirzakhani with or without hijab but we will arrest you when you come back to Iran because of your unveiled photo."

Many Iranians, however, praised Rouhani for the tweet. One said it showed the president was valuing her brain over her hijab. The US state department's Persian spokesman, Alan Eyre, also congratulated Mirzakhani on Facebook.

But despite praise online, local media in Iran struggled with the coverage of Mirzakhani's win. The state-run Iran newspaper digitally retouched her photograph to put a scarf over her head while the reformist Shargh published a sketch showing only her face.

Mirzakhani's win also sparked debates about the country's brain drain and the large exodus of Iranian Olympiad medallists to the west, especially to the US and Canada. At least three survivors of the 1998 bus crash, including Mirzakhani and her friend Roya Beheshti Zavareh have since left their country. According to the latest official figures, more than 70% of Iranian Olympiad medallists in physics and maths have left Iran, some working in top American universities.

Behrang Noohi from London's Queen Mary University who helped Mirzakhani to prepare for international Olympiads in the 1990s said the majority of talented Iranian intellectuals he knows have opted to stay abroad.

"From the people I know around me, almost 20 Iranians, only three people have decided to go back to Iran after their studies," he told the Guardian. Noohi, who has kept in touch with Mirzakhani, said her talent was conspicuous from her early years.

Mohammadreza Jalaeipour from Oxford University said Mirzakhani's success was also testament to the work done by Iran's education system. "This is the very education system that identified her and invested on her for many years," he said, referring to Mirzakhani's time in Iran where she won two gold maths international Olympiads.

Women face many restrictions in Iran in their social life, but Jalaeipour told the Guardian that women in Iranian universities enjoy same opportunities during their education. "As a graduate student at Harvard, I had to explain quite a few times that I was allowed to attend a university as a woman in Iran," Mirzakhani has said in an interview.

Last year, as Rouhani visited New York for the UN general assembly, he promised Iranian exiles to facilitate their return, saying all Iranians had right to access their home country. That promise is yet to materialise amid opposition from hardliners. And this week's news about Mirzakhani revived that issue.

Mirzakhani is married to a Czech scientist and has a daughter and many wondered if their marriage could be recognised in Iran, where woman are not allowed to marry non-Muslim, and if they could take their daughter (a child of a marriage deemed invalid by Iranian officials) to the country. However, men can marry women of foreign nationalities. Iran's semi-official Isna news agency said she has been invited to participate in an Iranian maths seminar.

Others spoke of the risk Iranians going back. Omid Kokabee, an award-winning Iranian physicist with the University of Texas, has been imprisoned and sentenced to ten years in jail after returning to Iran. He remains behind bars.