In eleventh-century Persia, it is said that three school friends pledged to serve their country and share their fortunes. Very different fortunes, it turned out.

Nizam al-Mulk became prime minister to two consecutive Persian kings. He built a network of roads across the country, and established the chain of 'Nizamiyya' schools, which taught theology, science and mathematics, adhering to a national curriculum.

Hassan-i Sabbah became the head of a fanatical religious group, the Hashshashin, which operated an almost independent government, protected by a string of castles. The many attempts by Persian kings to overthrow the Hashshashin failed, and Nizam al-Mulk was eventually assassinated by Sabbah's followers.

Omar Khayyam became the greatest astronomer and mathematician of his age. He invented, for example, the Khayyam triangle — better known as the Pascal triangle, after Blaise Pascal who described it hundreds of years later. Khayyam also provided his country with a solar calendar, more accurate than the gregorian calendar we use today. And he became one of Persia's most popular poets.

In the millennium since the three school friends parted company, the country we now know as Iran has witnessed a sometimes glorious, often sad, political history. Along with the rest of the Middle East, Iran's scientific power declined as Europe's ascended with the Renaissance. But the nation's cultural respect for study never died.

Science regained its foothold during the 1970s, under the Shah, even though his oppressive regime drove many intellectuals into exile. It faltered at the start of the Islamic revolution in 1979, but gained momentum in the 1990s when Iran became the most scientifically productive country in the Middle East apart from Israel. About 4,000 papers from Iran were published in 2005, according to the Institute for Scientific Information, compared with just over 500 in 1995. (Nature's first all-Iranian research paper was published last week.)

Perhaps the rise of science relates to the importance that Iran's government attaches to the development of nuclear technology. Many regard Iran's interest in these technologies with extreme suspicion. Nonetheless, Iran's embrace of science should be welcomed.

The educated young in Iran will still go their own individual ways, usually for good, sometimes for bad. But there is once again the opportunity for a privileged few to shine as scientists, if they can cope with the low pay and poor infrastructure that prevail outside the handful of elite institutions, and can sidestep the many problems caused by US sanctions.

One practical advantage for science in Muslim countries is the lack of direct interference of religious doctrine, such as exists in many Christian countries. There has never, for example, been a debate about darwinian evolution, and human embryonic stem-cell research is constrained by humanistic rather than religious ethics. The Royan Institute in Iran was the first in the Middle East to develop a human embryonic stem-cell line, using spare embryos from its in vitro fertilization programme.

The recent dramatic rise in scientific productivity coincided with the relaxing of a stern Islamic regime under reformist president Mohammad Khatami. When hard-line Islamist Mahmoud Ahmadinejad was elected president last year, some scientists felt nervous, especially, no doubt, when he replaced the presidents of all the universities with worryingly inexperienced people. But the regime has so far shown a strong commitment to higher education. One of its first acts was to wipe out the debts accrued by universities, where female students now outnumber males, even in some areas of hard science. Ahmadinejad has also taken significant steps to prepare for an expansion of university student numbers. And he has not made cuts to research funds, which had increased over the past decade.

But will he maintain growth, given other pressing priorities in today's Iran? If not, many young scientists trained in the recent good years and now undertaking postdoctoral research abroad will have no prospects if they return home. An opportunity would be lost. So here's hoping that he avoids the need for these lines of Khayyam as a lament:

Alas that spring should vanish with the rose

That youth's sweet-scented manuscript should close!