In 807 the Abbasid caliph in Baghdad, Harun al-Rashid, sent Charlemagne a gift the like of which had never been seen in the Christian empire: a brass water clock. It chimed the hours by dropping small metal balls into a bowl. Instead of a numbered dial, the clock displayed the time with 12 mechanical horsemen that popped out of small windows, rather like an Advent calendar. It was a thing of beauty and ingenuity, and the Frankish chronicler who recorded the gift marvelled how it had been ‘wondrously wrought by mechanical art’. But given the earliness of the date, what’s not clear is quite what he might have meant by that.

Certain technologies are so characteristic of their historical milieux that they serve as a kind of shorthand. The arresting title credit sequence to the TV series Game of Thrones (2011-) proclaims the show’s medieval setting with an assortment of clockpunk gears, waterwheels, winches and pulleys. In fact, despite the existence of working models such as Harun al-Rashid’s gift, it was another 500 years before similar contraptions started to emerge in Europe. That was at the turn of the 14th century, towards the end of the medieval period – the very era, in fact, whose political machinations reportedly inspired the plot of Game of Thrones.

When mechanical clockwork finally took off, it spread fast. In the first decades of the 14th century, it became so ubiquitous that, in 1324, the treasurer of Lincoln Cathedral offered a substantial donation to build a new clock, to address the embarrassing problem that ‘the cathedral was destitute of what other cathedrals, churches, and convents almost everywhere in the world are generally known to possess’. It’s tempting, then, to see the rise of the mechanical clock as a kind of overnight success.

But technological ages rarely have neat boundaries. Throughout the Latin Middle Ages we find references to many apparent anachronisms, many confounding examples of mechanical art. Musical fountains. Robotic servants. Mechanical beasts and artificial songbirds. Most were designed and built beyond the boundaries of Latin Christendom, in the cosmopolitan courts of Baghdad, Damascus, Constantinople and Karakorum. Such automata came to medieval Europe as gifts from foreign rulers, or were reported in texts by travellers to these faraway places.

In the mid-10th century, for instance, the Italian diplomat Liudprand of Cremona described the ceremonial throne room in the Byzantine emperor’s palace in Constantinople. In a building adjacent to the Great Palace complex, Emperor Constantine VII received foreign guests while seated on a throne flanked by golden lions that ‘gave a dreadful roar with open mouth and quivering tongue’ and switched their tails back and forth. Next to the throne stood a life-sized golden tree, on whose branches perched dozens of gilt birds, each singing the song of its particular species. When Liudprand performed the customary prostration before the emperor, the throne rose up to the ceiling, potentate still perched on top. At length, the emperor returned to earth in a different robe, having effected a costume change during his journey into the rafters.

The throne and its automata disappeared long ago, but Liudprand’s account echoes a description of the same marvel that appears in a Byzantine manual of courtly etiquette, written – by the Byzantine emperor himself, no less – at around the same time. The contrast between the two accounts is telling. The Byzantine one is preoccupied with how the special effects slotted into certain rigid courtly rituals. It was during the formal introduction of an ambassador, the manual explains, that ‘the lions begin to roar, and the birds on the throne and likewise those in the trees begin to sing harmoniously, and the animals on the throne stand upright on their bases’. A nice refinement of royal protocol. Liudprand, however, marvelled at the spectacle. He hazarded a guess that a machine similar to a winepress might account for the rising throne; as for the birds and lions, he admitted: ‘I could not imagine how it was done.’

Other Latin Christians, confronted with similarly exotic wonders, were more forthcoming with theories. Engineers in the West might have lacked the knowledge to copy these complex machines or invent new ones, but thanks to gifts such as Harun al-Rashid’s clock and travel accounts such as Liudprand’s, different kinds of automata became known throughout the Christian world. In time, scholars and philosophers used their own scientific ideas to account for them. Their framework did not rely on a thorough understanding of mechanics. How could it? The kind of mechanical knowledge that had flourished since antiquity in the East had been lost to Europe following the decline of the western Roman Empire.

Instead, they talked about what they knew: the hidden powers of Nature, the fundamental sympathies between celestial bodies and earthly things, and the certainty that demons existed and intervened in human affairs. Arthur C Clarke’s dictum that any sufficiently advanced technology is indistinguishable from magic was rarely more apposite. Yet the very blurriness of that boundary made it fertile territory for the medieval Christian mind. In time, the mechanical age might have disenchanted the world – but its eventual victory was much slower than the clock craze might suggest. And in the meantime, there were centuries of magical machines.

In the medieval Latin world, Nature could – and often did – act predictably. But some phenomena were sufficiently weird and rare that they could not be considered of a piece with the rest of the natural world. They therefore were classified as preternatural: literally, praeter naturalis or ‘beyond nature’.

What might fall into this category? Pretty much any freak occurrence or deviation from the ordinary course of things: a two-headed sheep, for example. Then again, some phenomena qualified as preternatural because their causes were not readily apparent and were thus difficult to know. Take certain hidden – but essential – characteristics of objects, such as the supposedly fire-retardant skin of the salamander, or the way that certain gems were thought to detect or counteract poison. Magnets were, of course, a clear case of the preternatural at work.

If the manifestations of the preternatural were various, so were its causes. Nature herself might be responsible – just because she often behaved predictably did not mean that she was required to do so – but so, equally, might demons and angels. People of great ability and learning could use their knowledge, acquired from ancient texts, to predict preternatural events such as eclipses. Or they might harness the secret properties of plants or natural laws to bring about certain desired outcomes. Magic was largely a matter of manipulating this preternatural domain: summoning demons, interpreting the stars, and preparing a physic could all fall under the same capacious heading.

All of which is to say, there were several possible explanations for the technological marvels that were arriving from the east and south. Robert of Clari, a French knight during the disastrous Fourth Crusade of 1204, described copper statues on the Hippodrome that moved ‘by enchantment’. Several decades later, Franciscan missionaries to the Mongol Empire reported on the lifelike artificial birds at the Khan’s palace and speculated that demons might be the cause (though they didn’t rule out superior engineering as an alternative theory).

Does a talking statue owe its powers to celestial influence or demonic intervention?

Moving, speaking statues might also be the result of a particular alignment of planets. While he taught at the cathedral school in Reims, Gerbert of Aurillac, later Pope Sylvester II (999-1003), introduced tools for celestial observation (the armillary sphere and the star sphere) and calculation (the abacus and Arabic numerals) to the educated elites of northern Europe. His reputation for learning was so great that, more than 100 years after his death, he was also credited with making a talking head that foretold the future. According to some accounts, he accomplished this through demonic magic, which he had learnt alongside the legitimate subjects of science and mathematics; according to others, he used his superior knowledge of planetary motion to cast the head at the precise moment of celestial conjunction so that it would reveal the future. (No doubt he did his calculations with an armillary sphere.)

Because the category of the preternatural encompassed so many objects and phenomena, and because there were competing, rationalised explanations for preternatural things, it could be difficult to discern the correct cause. Does a talking statue owe its powers to celestial influence or demonic intervention? According to one legend, Albert the Great – a 13th-century German theologian, university professor, bishop, and saint – used his knowledge to make a prophetic robot. One of Albert’s brothers in the Dominican Order went to visit him in his cell, knocked on the door, and was told to enter. When the friar went inside he saw that it was not Brother Albert who had answered his knock, but a strange, life-like android. Thinking that the creature must be some kind of demon, the monk promptly destroyed it, only to be scolded for his rashness by a weary and frustrated Albert, who explained that he had been able to create his robot because of a very rare planetary conjunction that happened only once every 30,000 years.

In legend, fiction and philosophy, writers offered explanations for the moving statues, artificial animals and musical figures that they knew were part of the world beyond Latin Christendom. Like us, they used technology to evoke particular places or cultures. The golden tree with artificial singing birds that confounded Liudprand on his visit to Constantinople appears to have been a fairly common type of automaton: it appears in the palaces of Samarra and Baghdad and, later, in the courts of central India. In the early 13th century, the sultan of Damascus sent a metal tree with mechanical songbirds as a gift to the Holy Roman Emperor Frederick II. But this same object also took root in the Western imagination: we find writers of fiction in medieval Europe including golden trees with eerily lifelike artificial birds in many descriptions of courts in Babylon and India.

In one romance from the early 13th century, sorcerers use gemstones with hidden powers combined with necromancy to make the birds hop and chirp. In another, from the late 12th century, the king harnesses the winds to make the golden branches sway and the gilt birds sing. There were several different species of birds represented on the king’s fabulous tree, each with its own birdsong, so exact that real birds flocked to the tree in hopes of finding a mate. ‘Thus the blackbirds, skylarks, jaybirds, starlings, nightingales, finches, orioles and others which flocked to the park in high spirits on hearing the beautiful birdsong, were quite unhappy if they did not find their partner!’

Of course, the Latin West did not retain its innocence of mechanical explanations forever. Three centuries after Gerbert taught his students how to understand the heavens with an armillary sphere, the enthusiasm for mechanical clocks began to sweep northern Europe. These giant timepieces could model the cosmos, chime the hour, predict eclipses and represent the totality of human history, from the fall of humankind in the Garden of Eden to the birth and death of Jesus, and his promised return.

Astronomical instruments, like astrolabes and armillary spheres, oriented the viewer in the cosmos by showing the phases of the moon, the signs of the zodiac and the movements of the planets. Carillons, programmed with melodies, audibly marked the passage of time. Large moving figures of people, weighted with Christian symbolism, appear as monks, Jesus, the Virgin Mary. They offered a master narrative that fused past, present and future (including salvation). The monumental clocks of the late medieval period employed cutting-edge technology to represent secular and sacred chronology in one single timeline.

Secular powers were no slower to embrace the new technologies. Like their counterparts in distant capitals, European rulers incorporated mechanical marvels into their courtly pageantry. The day before his official coronation in Westminster Abbey in 1377, Richard II of England was ‘crowned’ by a golden mechanical angel – made by the goldsmiths’ guild – during his coronation pageant in Cheapside.

And yet, although medieval Europeans had figured out how to build the same kinds of complex automata that people in other places had been designing and constructing for centuries, they did not stop believing in preternatural causes. They merely added ‘mechanical’ to the list of possible explanations. Just as one person’s ecstatic visions might equally be attributed to divine inspiration or diabolical trickery, a talking or moving statue could be ascribed to artisanal or engineering know-how, the science of the stars, or demonic art. Certainly the London goldsmiths in 1377 were in no doubt about how the marvellous angel worked. But because a range of possible causes could animate automata, reactions to them in this late medieval period tended to depend heavily on the perspective of the individual.

At a coronation feast for the queen at the court of Ferdinand I of Aragon in 1414, theatrical machinery – of the kind used in religious Mystery Plays – was used for part of the entertainment. A mechanical device called a cloud, used for the arrival of any celestial being (gods, angels and the like), swept down from the ceiling. The figure of Death, probably also mechanical, appeared above the audience and claimed a courtier and jester named Borra for his own. Other guests at the feast had been forewarned, but nobody told Borra. A chronicler reported on this marvel with dry exactitude:

Death threw down a rope, they [fellow guests] tied it around Borra, and Death hanged him. You would not believe the racket that he made, weeping and expressing his terror, and he urinated into his underclothes, and urine fell on the heads of the people below. He was quite convinced he was being carried off to Hell. The king marvelled at this and was greatly amused.

Such theatrical tricks sound a little gimcrack to us, but if the very stage machinery might partake of uncanny forces, no wonder Borra was afraid.

Nevertheless, as mechanical technology spread throughout Europe, mechanical explanations of automata (and machines in general) gradually prevailed over magical alternatives. By the end of the 17th century, the realm of the preternatural had largely vanished. Technological marvels were understood to operate within the boundaries of natural laws rather than at the margins of them. Nature went from being a powerful, even capricious entity to an abstract noun denoted with a lower-case ‘n’: predictable, regular, and subject to unvarying law, like the movements of a mechanical clock.

This new mechanistic world-view prevailed for centuries. But the preternatural lingered, in hidden and surprising ways. In the 19th century, scientists and artists offered a vision of the natural world that was alive with hidden powers and sympathies. Machines such as the galvanometer – to measure electricity – placed scientists in communication with invisible forces. Perhaps the very spark of life was electrical.

Even today, we find traces of belief in the preternatural, though it is found more often in conjunction with natural, rather than artificial, phenomena: the idea that one can balance an egg on end more easily at the vernal equinox, for example, or a belief in ley lines and other Earth mysteries. Yet our ongoing fascination with machines that escape our control or bridge the human-machine divide, played out countless times in books and on screen, suggest that a touch of that old medieval wonder still adheres to the mechanical realm.