For many, millipedes are amazing creatures, a marvel of natural engineering, purveyors of the most legs on the planet.

But millipedes are amazing for another, less well-known reason. Many species create and use chemical weapons against their enemies, in ways that scientists are only beginning to understand.

According to local lore, some can blind chickens. For some animals, a few millipedes are deadly to the touch. There are millipedes that seem immune to the poisonous effects of cyanide. Worse they manufacture and use the chemical against their foes. And some may even sedate their enemies.

The extent of their chemical warfare is revealed in a new study published in the journal Biological Systematics and Ecology by biology professor and millipede expert William Shear of Hampden-Sydney College in Virginia, the US.

Millipedes are a diverse group of arthropods, and were among the earliest animals to walk on land. Some long extinct species grew to more than 2 metres long. All have two pairs of legs on most of their body segments, which differentiate them from centipedes, which only have one pair.

Some lack chemical defences. Instead they have other means of defending against predators and parasites. Often this involves curling their bodies into a tight ball, hiding their more delicate legs within an armoured exoskeleton.

As a group, millipedes can produce a dazzling array of chemicals

Another defence tactic used by the species Polyxenus fasciculatus is to shed bristly hairs, which can irritate and entangle ants. The more the ants struggle, the more the bristles hook onto the ants’ own hairs, eventually binding them in a mesh.

But different orders of millipedes, including the Glomerida and Helminthomorpha, have independently evolved the ability to create chemical weapons.

The first review of this ability was written in 1900, by the biologist Orator F Cook, who coined the term speciation, the process by which new species arise from existing ones.

As a group, millipedes can produce a dazzling array of chemicals, including alkaloids, quinones, ketones, terpenes, esters, phenols and various acids, as well as specifically insidious chemicals such as hydrogen cyanide (HCN).

This ability is important to millipedes, which spend their lives either eating fungi or plant fluids, or decaying and dead plant matter. A few prey on small animals, but almost none can run fast enough to escape their enemies (although there is one species that can jump a few inches, momentarily leaping out of sight of ants pursuing it).

Another defence tactic is to shed bristly hairs, which can irritate and entangle ants

So they either hide, camouflaging themselves. Or they fight off their enemies.

They can do this physically, growing sharp teeth or spikes, often supplemented by rows or groups of long spines, along their bodies. Though not yet proven, it seems likely that these spikes deter predation by birds, reptiles, amphibians or small mammals.

Or they can do it chemically.

They evolved this ability early on. Fossils of millipedes have been discovered from the Devonian period (420-360 million years ago) with ozopores, openings in the body through which chemicals could be excreted.

Modern millipedes have glands they can use to force out irritating or poisonous chemicals.

Some millipede species secrete sticky substances that bind to and trap any intruders, such as ants. Others are less passive.

It may take up to four months for some species to replenish their chemical stocks

There are references in the scientific literature to indigenous peoples of Mexico grinding down millipedes and using their bodies to poison the tips of arrows. Others have made a link between people in Zambia using “very large curled up dead millipedes” to scrub cooking pots, and resulting incidences of throat cancer, supposedly triggered by irritants in the arthropods.

These anecdotes are difficult to verify and may be exaggerated. But Professor Shear’s review lists the various ways millipedes can create and use chemical weapons.

One group of millipedes are known as glomeridans. They belong to the pill millipedes, which resemble woodlice (pill bugs) and can curl into a protective ball. After rolling up, these millipedes squeeze their muscles, forcing out secretions from glands along the length of their body.

Producing these chemicals may be expensive and it may take up to four months for some species to replenish their chemical stocks. That means they may only be able to unleash chemical weapons on their enemies a few times a year, when they really need to.

Some of their secretions are toxic, with perhaps the most powerful being hydrogen cyanide

Another group, known as juliform millipedes, eject their chemical weapons differently. Some just let the chemicals passively ooze from their glands. But a few may actively spray chemicals onto their victims. Some larger species can shoot their spray up to 50cm away, though it not yet clear how they do it.

Juliform millipedes are the only group known to produce quinones as a chemical repellent, and another enigma is how they spray out chemicals called benzoquinones. These chemicals are solid at environmental temperatures, and we don’t yet understand how millipedes liquefy them.

Some millipedes, such as Leonardesmus injucundus that lives in Washington State in the US, can also produce phenolic compounds, which are so repellent they be detected by humans standing 2 metres away, though the millipedes are only about 1 centimetre long.

Millipedes are attacked by ants, beetles (both adults and larvae), bugs, spiders, slugs and vertebrates that hunt by sight, including birds, mammals, reptiles and amphibians.

Even being confined in a small space with certain types of millipede, such as a collecting jar, can prove fatal to many species of insect and even small vertebrates

Yet their chemical deterrents can be extremely effective. Many deter ants, and benzoquinones are highly irritating to vertebrates, not only to mucous membranes and the eyes, but also to intact skin.

According to one study published in 1936, cited by Professor Shear, it was common knowledge among natives of Hispaniola that large spirobolidan millipedes could blind chickens and other animals with their sprayed secretions.

Some of their secretions are toxic, with perhaps the most powerful being hydrogen cyanide, which is produced by polydesmid millipedes, the largest order that contains some 3500 species.

A single Apheloria millipede weighing about 1 gram can produce up to 600 micrograms of HCN, 18 times the lethal dose for a 300 gram pigeon and six times that for a 25 gram mouse. Even being confined in a small space with certain types of millipede, such as a collecting jar, can prove fatal to many species of insect and even small vertebrates.

If HCN doesn’t work, and there is some evidence it doesn’t deter certain ants, then millipedes use a second chemical, such as benzaldehyde.

“It may be that polydesmidans need defence against both insect and vertebrate predators, with benzaldehyde repelling ants and HCN working primarily against vertebrates,” suggests Professor Shear.

In an amazing but hugely practical adaptation, polydesmid millipedes also happen to be immune to poisoning by their own hydrogen cyanide. Initially it was thought they did it by closing down the openings they use to breathe, to ensure none gets inside their own body. But it now seems likely that millipedes have evolved to be biochemically resistant to cyanide, and they can somehow convert it into other innocuous chemicals.

Marvels of natural engineering indeed.

Follow Matt Walker and BBC Earth on twitter.