This deadly effect occurred only if the flies consumed alcohol after the wasps laid eggs in them. Taking in alcohol beforehand, by contrast, had little effect. This discovery led Dr. Schlenke to wonder if the flies might seek out alcohol to kill the wasps, using it like a medical drug. “I wondered if they were smart enough to know that,” he said.

To find out, he and his colleagues filled petri dishes with alcohol-rich food on one side and alcohol-free food on the other. They then placed flies that did not have wasps inside them on the alcohol-free side. A day later, they found that 30 percent of the flies had crawled over to the side with alcohol. When they repeated the experiment with wasp-infested flies, 80 percent of the flies headed for the spirits. “There’s a big difference there,” Dr. Schlenke said.

Likewise, when the flies started out on the alcohol side of the dish, 40 percent of the healthy flies crawled to the other side after 24 hours. Many infected larvae started moving to the other side as well, but then returned to the alcohol. Dr. Schlenke speculates that they were exploring for even higher alcohol concentrations that would be even more toxic to their parasites.

“They know the wasps are infecting them, and they seek out the alcohol,” Dr. Schlenke said. “The flies self-medicate by getting schnockered.”

Some wasps appear to have evolved ways around this tipsy defense. Dr. Schlenke repeated these experiments on another species, L. boulardi, which unlike the other wasp can lay its eggs only in D. melanogaster. Dr. Schlenke found that the specialist wasp L. boulardi suffered far less when its host consumed alcohol. Only 10 percent of its larvae died, compared with 65 percent for L. heterotoma. Dr. Schlenke suspects that its specialization allowed L. boulardi to overcome the alcohol. “The wasps are tracking their hosts over evolutionary time,” he said.

“This article is exciting in several ways,” said Michael Singer, a biologist at Wesleyan University who was not involved in the study. Over the years, scientists have gathered a few examples of animals medicating themselves. Chimpanzees eat plants with antiparasitic compounds when they get intestinal worms, for example. Dr. Singer and his colleagues have shown that woolly bear caterpillars go out of their way to feed on toxic plant leaves when parasitic flies lay eggs in them. But Dr. Schlenke’s research is the first to show that an animal uses alcohol as medicine.