For me, it was hornets. One afternoon when I was 12, I ran into an overgrown field near a friend’s house and kicked a hornet nest the size of a football. An angry squadron of insects clamped on to my leg; their stings like scorching needles. I swatted the hornets away and ran for help, but within minutes I realised that something else was happening. A constellation of pink stars had appeared around the stings. The hives swelled and new ones began appearing farther up my legs. I was having an allergic reaction. My friend’s mother gave me antihistamines and loaded me into her van. We set out for the county hospital, my dread growing as we drove. I imagined the hives reaching my throat and sealing it shut.

I lived to tell the tale: my hives subsided, leaving behind a lingering fear of hornets. But an allergy test confirmed that I was sensitive to the insects. The doctor said I might not be so fortunate the next time, handed me an EpiPen and told me to ram the syringe into my thigh if I was stung again. The epinephrine would raise my blood pressure, open my airway – and perhaps save my life.

Anyone with an allergy has their origin story, a tale of how they discovered that their immune system goes haywire when some arbitrarily particular molecule gets into their body. There are hundreds of millions of these stories, and the list of allergens includes – but is not limited to – latex, gold, pollen, penicillin, insect venom, peanuts, papayas, jellyfish stings, perfume, eggs, the faeces of house mites, pecans, salmon, beef and nickel.

Once these substances trigger an allergy, the symptoms can run the gamut from annoying to deadly. Hay fever brings sniffles and stinging eyes; allergies to food can cause vomiting and diarrhoea. For an unlucky minority, allergies can trigger a potentially fatal whole-body reaction known as anaphylactic shock.

Sneezy does it: dandelions shed their seeds (PHILIPPE HUGUEN/AFP/Getty Images)

The collective burden of these woes is tremendous, yet the treatment options are limited. EpiPens save lives, but the available long-term treatments offer mixed results. Antihistamines can often reduce symptoms, but these drugs also cause drowsiness, as do some other treatments.

We might have more effective treatments if scientists understood allergies, but a maddening web of causes underlies allergic reactions. And there’s an even bigger mystery underlying this biochemical web: why do we even get allergies at all?

“That is exactly the problem I love,” Ruslan Medzhitov told me recently. “It’s very big, it’s very fundamental, and completely unknown.”

Medzhitov and I were wandering through his laboratory at the Yale School of Medicine. He has a boxer’s face – massive, circular, with a broad, flat nose – but he spoke with a soft elegance.

Over the past 20 years, he has made fundamental discoveries about the immune system, for which he has been awarded a string of major prizes. Now he is turning his attention to a question that could change immunology yet again: why do we get allergies? No one has a firm answer, but what is arguably the leading theory suggests they are a misfiring of a defence against parasitic worms – which makes us miserable in the process.

Medzhitov thinks that’s wrong. Allergies are not simply a biological blunder but an essential defence against noxious chemicals – and one that has served our ancestors for tens of millions of years. It’s controversial, he acknowledges. But he’s also confident that history will prove him right.

The physicians of the ancient world knew about allergies. 3,000 years ago, Chinese doctors described a “plant fever” that caused runny noses in autumn. There is evidence that the Egyptian pharaoh Menes died from the sting of a wasp in 2641 BCE. Two and a half millennia later, the Roman philosopher Lucretius wrote, “What is food to one is to others bitter poison.”

But it was a little more than a century ago that scientists realised these diverse symptoms are different heads on the same hydra. By then researchers had discovered that many diseases are caused by bacteria and other pathogens, and that we fight these invaders with an immune system – an army of cells that can unleash deadly chemicals and precisely targeted antibodies. They soon realised that the immune system can also cause harm.

In the early 1900s, the French scientists Charles Richet and Paul Portier injected small doses of poison from sea anemones into dogs, then waited a week or so before delivering an even smaller dose. Within minutes, the dogs went into shock and died. Instead of protecting the animals from harm, the immune system appeared to make them more susceptible.

Other researchers observed that some medical drugs caused hives and other symptoms. And this sensitivity increased with exposure – the opposite of the protection antibodies provided against diseases. And in the decades that followed, scientists discovered that the molecular stages of these reactions were remarkably similar. The process begins when an allergen lands on one of the body’s surfaces – skin, eye, nasal passage, mouth, airway or gut. These surfaces are loaded with immune cells that act as border sentries. When a sentry encounters an allergen, it first engulfs and demolishes the invader, then decorates its outer surface with fragments of the substance. Next the cell locates some lymph tissue. There it passes on the fragments to other immune cells, which produce a distinctive fork-shaped antibody, known as immunoglobulin E, or IgE.

These antibodies will trigger a response if they encounter the allergen again. The reaction begins when an antibody activates something called a mast cell, which then blasts out a barrage of chemicals. Some of these latch onto nerves, triggering itchiness and coughing. Sometimes mucus is produced. Airway muscles can contract, making it hard to breathe.

This picture, built up in labs over the past century, answered the “How?” Left unanswered, however, was “Why?” It was hard to see how natural selection could have produced allergies. Reacting to harmless things with a huge immune response probably wouldn’t have aided the survival of our ancestors. Also, only some people have allergies and only some substances are allergens. Sometimes people develop allergies relatively late in life; sometimes childhood allergies disappear. And for decades, nobody could even figure out what IgE was for. It was as if we evolved one special kind of antibody just to make us miserable.

One early clue came in 1964. A parasitologist named Bridget Ogilvie was investigating how the immune system repelled parasitic worms, and she noticed that rats infected with worms produced large amounts of what would later be called IgE. Subsequent studies revealed that the antibodies signalled the immune system to unleash a damaging assault on the worms.

Parasitic worms represent a serious threat – not just to rats, but to humans too. Hookworms can drain off blood from the gut. Liver flukes can damage liver tissue and cause cancer. Tapeworms can cause cysts in the brain. Before modern public health and food safety systems, our ancestors faced a lifelong struggle against these worms, as well as ticks and other parasitic animals. During the 1980s, several scientists argued forcefully for a link between these parasites and allergies. Perhaps our ancestors evolved an ability to recognise the proteins on the surface of worms and to respond with IgE antibodies. The antibodies primed immune system cells in the skin and gut to quickly repel any parasite trying to push its way in. “You’ve got about an hour to react very dramatically in order to reduce the chance of these parasites surviving,” said David Dunne, a parasitologist at the University of Cambridge.

According to the worm theory, the proteins of parasitic worms are similar in shape to other molecules we regularly encounter in our lives. If we encounter those molecules, we mount a pointless defence. “Allergy is just an unfortunate side-effect,” says Dunne.

Dandelion seeds blow in the wind in Godewaersvelde, northern France (PHILIPPE HUGUEN/AFP/Getty Images)

When he was an immunologist in training, Medzhitov was taught the worm theory of allergies. But 10 years ago he started to develop doubts. So he began thinking about a theory of his own. Mostly, he thought about how our bodies perceive the outside world. We can recognise patterns of photons with our eyes and patterns of air vibrations with our ears.

To Medzhitov, the immune system was another pattern recognition system – one that detected molecular signatures. Then he came across a 1989 essay by Charles Janeway, an immunologist at Yale. Titled ‘Approaching the Asymptote? Evolution and revolution in immunology’, it would change his life.

At the time, Janeway was arguing that antibodies have a big drawback: it takes days for the immune system to develop an effective antibody against a new invader. He speculated that the immune system might have another line of defence that could offer faster protection.

Medzhitov had been thinking about the same thing, and he immediately emailed Janeway. Janeway responded, and they began an exchange that would ultimately bring Medzhitov to New Haven, Connecticut, in 1994, to become a postdoctoral researcher in Janeway’s lab. (Janeway died in 2003.) Soon he and Janeway discovered a new class of sensor on the surface of a certain kind of immune cell. Confronted with an invader, the sensors would clasp on to the intruder and trigger a chemical alarm that promoted other immune cells to search the area for pathogens to kill. It was a fast, accurate way to sense and remove bacterial invaders.

Medzhitov kept thinking after he and Janeway discovered the toll-like receptors (as they are now known). If the immune system has special sensors for some invaders, perhaps it had undiscovered sensors for others. That’s when he started thinking about parasitic worms, IgE and allergies. And when he thought about them, things didn’t add up.

Two bees watch from their hive at the Blackhorse Apairy Beekeeping Centre in St Johns, near Woking (Getty Images)

First, some studies suggest that IgE isn’t actually essential to fight parasitic worms. Second, Medzhitov was sceptical that allergens mimic parasite proteins. A lot of allergens, such as nickel or penicillin, have no possible counterpart in parasite biology. So maybe what ties allergens together was not their shape, but what they do.

We know that allergens often cause physical damage. They rip open cells, irritate membranes, slice proteins into tatters. Maybe, Medzhitov thought, allergens do so much damage that we need a defence against them.

“If you think of all the major symptoms of allergic reactions – runny noses, tears, sneezing, coughing, itching, vomiting and diarrhoea – all of these things have one thing in common,” said Medzhitov. “They all have to do with expulsion”. So perhaps allergies weren’t the body going haywire; they were the body’s strategy for getting rid of allergens.

Together with two of his students, Medzhitov published his theory in Nature in 2012. Then he began testing it. First he injected mice with PLA2, an allergen found in bee venom that tears apart cell membranes. As Medzhitov had predicted, the animals’ immune systems didn’t respond to PLA2 itself. Only when PLA2 ripped open cells did the immune system produce IgE antibodies.

Another prediction of Medzhitov’s theory was that these antibodies would protect the mice, rather than just make them ill. To test this, he followed the initial injection of PLA2 with a second, much bigger dose. If the animals had not previously been exposed to PLA2, their temperature plunged, sometimes fatally. But the previously exposed mice marshalled an allergic reaction that, for reasons that aren’t yet clear, lessened the impact.

Yale scientist Ruslan Medzhitov

Still, the experiments left a lot unanswered. How precisely does the damage caused by allergens lead to an IgE response? And how does IgE protect us?

Medzhitov predicts that his latest experiments will show that allergen detection is like a burglar alarm. “You can detect a burglar, not by recognising his face, but by a broken window,” he says. The damage caused by an allergen rouses the immune system, which gathers up molecules in the vicinity and makes antibodies to them. Now the criminal has been identified and can be more easily apprehended next time he tries to break in.

Allergies make a lot more sense in terms of evolution when seen as a burglar alarm, argues Medzhitov. Allergies would have protected our ancestors by flushing out toxins. And the discomfort our ancestors felt when exposed to these allergens might have led them to move to safer parts of their environment.

Like many adaptations, allergies weren’t perfect. They lowered the odds of dying from toxins but didn’t eliminate the risk. Sometimes the immune system overreacts dangerously, as Richet and Protier discovered. And the immune system might sometimes round up a harmless molecular bystander when it responded to an allergy alarm. But overall, Medzhitov argues, the benefits of allergies outstripped their drawbacks.

That balance shifted with the rise of modern Western life, he adds. As we created more synthetic chemicals, we exposed ourselves to a wider range of compounds, each of which could potentially cause damage and trigger an allergic reaction. Our ancestors could avoid allergens by moving to the other side of the forest, but we can’t escape so easily.

“In this particular case, the environment we’d have to avoid is living indoors,” says Medzhitov.

Over the next few years, he hopes to advance his proofs with another experiment. Sitting on a lab bench is a plastic box housing a pair of mice. There are dozens more in the basement of their building. Some of the mice are ordinary, but others have been genetically engineered to remove their ability to make IgE – so they can’t get allergies.

Medzhitov will be observing these allergy-free mice for the next couple of years. The animals may be spared the misery of hay fever caused by the pollen that will inevitably drift into their box on currents of air. But Medzhitov predicts they will be worse off for it. Unable to fight allergens, they will let toxic molecules pass into their bodies, to damage organs and tissues.

If this experiment works out, it could eventually lead to dramatic changes in how allergies are treated. “It might be that completely blocking allergic defences is a bad idea, Medzhitov says. Instead, allergists should be learning why some people turn a protective response into a hypersensitive one. “It’s the same as with pain,” says Medzhitov. “No pain at all is deadly; normal pain is good; too much pain is bad.”

For now, however, he would just be happy to get people to stop seeing allergies as a disease. “You’re sneezing to protect yourself. The fact that you don’t like the sneezing, that’s tough luck,” he says. “Evolution doesn’t care how you feel.”