Maryam Mirzakhani, an Iranian-born mathematician who was the first woman to win the coveted Fields Medal, has died in a US hospital after a battle with cancer. She was 40.

Mirzakhani' friend Firouz Naderi announced her death on Saturday on Instagram, and her relatives confirmed the death to the Mehr agency in Iran.

"A light was turned off today. It breaks my heart ..... gone far too soon," wrote Naderi, a former director of Solar Systems Exploration at NASA.

"A genius? Yes. But also a daughter, a mother and a wife," he added in a subsequent post.

Mirzakhani, a professor at Stanford University in California, died after the cancer she had been battling for four years spread to her bone marrow, Iranian media said.

In 2014 Mirzakhani won the Fields Medal, the equivalent of the Nobel Prize for Mathematics, which is awarded by the International Congress of Mathematicians.