The relay-race model of intellectual history is simple enough: a go-ahead culture picks up the torch, runs as far as it can, and hands the light of learning to a younger contender before sinking into exhaustion.

The ancient Greeks fan the flame of rational inquiry and surrender it to the Romans, who leave it to flicker. The Vandals and Visigoths snuff it out. But embers of scholarship still glow in the eastern empire of Byzantium, and when the Arabs emerge from the desert darkness and establish the fabulous empire of Islam, inquiring minds in Baghdad and Isfahan translate, preserve and annotate the wisdom of Ptolemy and Aristotle for the next six centuries. The sultans and satraps storm Europe with the sword, but with them too arrives the astrolabe, algebra and the glory that was Greece.

This is enough to light up the dark ages, ignite the Renaissance, and inflame modern science. The evidence is in the nouns: algebra, alchemy, alcohol and even the capital letters of astronomy and history, Aldebaran and Avicenna and the Almagest of Ptolemy.

So far, so familiar. But Jim al-Khalili's book does more than just enrich a familiar narrative: it brings alive the bubbling invention and delighted curiosity of the Islamic world. The Greeks certainly provide the thread for the story, but from such thread the Ummayyads and Abbasids wove their own astonishing fabric of discovery and enlightenment. Empires are built on bloodshed but survive on know-how. "The ink of the scholar is more sacred than the blood of the martyr," said the prophet Muhammad, and the empire founded in his name had a communication problem to solve before it could build its knowledge economy.

Persian or Pahlavi texts had to be translated into Arabic, among them studies of astrology, which may originally have been based on mathematics texts in Sanskrit. The new empire also needed Arabic versions of texts on geometry, engineering and arithmetic; it clashed with the Chinese, and from prisoners learned the art of papermaking. The first paper mills were established in Baghdad at the end of the eighth century: dyes, inks, glues and bindings followed. During and after the reign of Harun al-Rashid, the fabulous caliph of the so-called Arabian Nights, Persian, Arab, Christian and Jewish scholars all began to translate and publish medical and mathematical texts from Greek and Syriac as well as Persian and Indian scripts.

Around this time, Geber or Jabir ibn Hayyan the alchemist composed the Kitab al-Kimiya, a systematic examination of the nature of matter, which in 1144 would be translated into Latin by Robert of Chester as the Liber de compositione alchimiae. From Jabir we gain the word alkali, the distilling apparatus known as an alembic and – says Al-Khalili – perhaps even the word gibberish. Later Arabic texts delivered words we still use today: amalgam, borax, camphor, elixir. Whether Jabir counts as scientist or alchemist is an open question: within a generation, real science, intense scholarship and a palpable curiosity about the physical world began to emerge. Harun's successor Al-Ma'mun is linked with the founding of the House of Wisdom, a library, academy and translation factory that may have become at the time the largest repository of books in the world. Polymaths produced maps that showed the Indian Ocean and the Atlantic as open bodies of water, and tried to crack the meaning of ancient Egyptian hieroglyphs; they composed star charts, and adapted the Hindu number system to deliver the numerals we now use every day.

Not all Al-Khalili's heroes were Arabs: Omar Khayyam calculated the length of the solar year to 11 decimal places and composed in his native Persian a famous Treatise on Demonstration of Problems in Algebra, as well, of course, as those lines about the jug of wine, the loaf of bread and thou. Aristotle, too, lives on in this story: he appears in a dream to a caliph's son, and he fascinates generations of Islamic scholars. They were also people of their time. They accepted the theories of the four humours and the geocentric universe. But Ibn al-Haytham's Book of Optics pioneered the study of refraction and applied mathematics to a theory of vision; his successor Ibn Mu'adh used Euclidian geometry to calculate the height of the atmosphere at 52 miles (it is about 62 miles).

The tradition of inquiry and scholarship reaches far beyond Baghdad: to Samarkand and Bokhara, to Cairo and Cordoba. In the 10th century, in Andalusia, Al-Zahrawi devised the forceps, speculum and bonesaw, pioneered inhalant anaesthetics in the form of sponges soaked with cannabis and opium, and even described the first syringe. Ibn al-Nafis in the 13th century anticipated Harvey and described the pulmonary transit of the blood from the right side of the heart, via the lungs, to the left.

Al-Khalili is a Baghdad-born British physicist: his command of Arabic and mathematical physics invests his story with sympathy as well as authority. He is careful to put Arabic science in its context; he tries not to claim too much for his heroes and his attention to detail and fairness is rewarding. The metaphor of science as a relay race is exposed as unsatisfactory: cultures overlap, enrich and stimulate each other, and 10th-century Arab scholars greedy for understanding form a community with 16th-century Elizabethans or 21st-century Cambridge dons. The easy equation of Islam and wilful ignorance never made sense – empires are not sustained by ignorance – but even in the 11th century, the rationalists felt it necessary to defend reason.

The Persian Al-Biruni, who measured the height of a mountain and the angle of dip of the horizon to calculate the circumference of the planet to within an accuracy of 1%, warned that the extremist "would stamp the sciences as atheistic and would proclaim that they led people astray, in order to make ignoramuses of them, and to hate the sciences. For this will help him conceal his own ignorance, and to open the door to the complete destruction of the sciences and the scientists."

He might have been talking about the mullahs of modern Tehran, or the ranters of the US religious right. In the end, Arabic science did falter. The flame was picked up by Copernicus and Galileo, by William Harvey and Isaac Newton. In 2005, scientists from 17 Arab countries produced 13,444 scientific publications. Harvard University alone that year produced 15,455.