At Halloween, images of witches flying across the night sky astride broomsticks are everywhere. The myth that witches could fly with the help of their broomsticks has been around for centuries, but could its origins be traced to a chemical in over-the-counter medicines found in most of our homes?

In the heyday of witch-hunting hysteria, talk of a mysterious "flying ointment" began to gather momentum among those investigating witchcraft. This herbal unguent, rubbed into the skin, was purported to confer the power of flight, transporting witches to their Sabbat gatherings.

The Spanish court physician Andrés de Laguna, writing in the 16th century, claimed to have taken from the home of a couple accused of witchcraft "a pot full of a certain green ointment … composed of herbs such as hemlock, nightshade, henbane, and mandrake."

That would have been a potent mixture. Nightshade, henbane and mandrake are some of the most toxic plants in the family Solanaceae. Nightshade (Atropa belladonna) is immediately recognisable for its deep purple fruit and was said to be tended by the Devil himself. Like its close relatives henbane (Hyoscymaus niger) and mandrake (Mandragora officinarum), its leaves and berries are packed with chemicals called tropane alkaloids.

One of these, scopolamine (also known as hyoscine), is the active ingredient of travel-sickness medications such as Boot's Travel Calms and the skin patch Scopoderm. Tropane alkaloids are unremarkable additions to a modern medicine cabinet, but if you took the raw plant material and pounded it in molten fat, you'd extract an uncontrolled mixture of the alkaloids in their pure, base form. You will have created the green ointment of de Laguna's alleged witch.

Scopolamine and its close cousin atropine are "muscarinic antagonists" – they bind to receptors in the nervous system that would, ordinarily, bind to the neurotransmitter acetylcholine. Low doses of these chemicals will induce a dry mouth and dilated pupils – and relieve the nausea of travel sickness. But high doses can lead to antimuscarinic syndrome: a state of altered consciousness often characterised by delirium and intense hallucinations.

If contemporary accounts are to be believed, "witches" applied this hallucinogenic ointment with the handle of a broom, smearing the ointment onto the length of the broom and then rubbing the handle against their genitals and even inserting it into the vagina. As the drugs took effect, delusions of flight may have ensued while astride the broomstick's handle. It has been argued that this drug-induced delusion lies at the the root of the myth of witches' flight.

The pharmacology is sound. "Ointment would have been very effective as a delivery method for scopolamine," says Dr Randolph Arroo, head of research at Leicester School of Pharmacy, De Montfort University. "Alkaloids go through your skin into the bloodstream – consider nicotine patches." Tropane alkaloids easily cross the blood-brain barrier, acting on the central nervous system.

"Mucous membranes are particularly good at transporting drugs - that's why cocaine is snorted," he adds. "Vaginal application would be pretty efficient, and the effects of the drugs would be noticeable quite rapidly."

So the ointment may well have been capable of delivering powerful delusions of flight. But the image of hallucinating women astride brooms is so highly sexualised as to seem comic. Did some of those accused of witchcraft really apply flying ointment in this way?

Dr Andrew Sneddon, a historian at the University of Ulster, is sceptical. "Even among those few who did confess to witchcraft, there's not much evidence that they made potions for flight, or for other nefarious purposes," he says. Rather the opposite, in fact: "As far as I'm aware, the material culture of witchcraft, in terms of surviving artefacts, relates mainly to anti-bewitchment measures – amulets and such like – made by cunning folk."

Did the ointment even exist? It's hard to be sure. "Many writers of demonological tracts were convinced that witches flew with the aid of ointments. It's there in the Malleus Maleficarum [a 15th century treatise on the prosecution of witches], with witches using the fat of murdered children as the basic ingredient," says University of York historian Professor Jim Sharpe. Significantly, though, any such admission by a "witch" would have been made under torture.

According to Sharpe, twilight flight has been a remarkably persistent cultural reference, going back as far as the cult of the Roman goddess Diana. Moreover, Aztec shamans in 15th century Mexico used another tropane alkaloid-containing plant – Datura stramonium or thorn apple – to transport their souls on "a magical flight to mythic time and space", reports Bernard Ortiz de Montellano in Aztec Medicine, Health, and Nutrition.

We may never know for sure how the myth of the flying broomstick arose. But the pharmacological actions of scopolamine and atropine, extracted from local herbs, might well be at the heart of this iconic image. If so, the flight to the Sabbat would have been a delirious, drug-induced hallucination – a dream of the deadly nightshade, given contemporary, corporeal form in our ghoulish Halloween costumes.