San Francisco biologists have made a macabre discovery that might help explain the mysterious crash of honeybee populations: parasites that turn bees into zombies.

Infected bees go mad, abandoning their hive in a suicidal rush toward bright lights, according to a new study by San Francisco State researchers.

“It’s the flight of the living dead,” said lead investigator and biology professor John Hafernik, also president of the California Academy of Sciences.

The parasite, a tiny fly, has been found in bees from three-quarters of the 31 surveyed hives in the Bay Area — essentially, everywhere except Santa Clara and San Mateo counties.

In a plotline similar to a George Romero horror film, the fly deposits its eggs into the bee’s abdomen, then takes over. The hapless bees walk around in circles, with no apparent sense of direction. Some are unable to even stand on their legs.

“They kept stretching them out and then falling over,” Hafernik said. “It really painted a picture of something like a zombie.”

The bees’ demise may contribute to what’s known as Colony Collapse Disorder, the phenomenon of failing honeybee hives around the United States — and a great concern in the agricultural community, which depends on these pollinators.

Despite six years of intense research, scientists have been unable to find a single reason for colony collapse. Increasingly, they suspect that several factors, including viruses and fungus, may be to blame.

“This is one more piece in the puzzle,” said researcher and San Francisco State graduate student Jonathan Ivers. “But no one has come up with a coherent picture of what the puzzle even looks like.”

The stakes are high, because honeybees are the primary pollinator of most nuts, vegetables and fruits. California’s $1 billion-a-year almond business, for instance, is entirely dependent on the honeybees.

“The agricultural economy of California would be devastated if honeybees disappeared,” Ivers said.

This creepy parasitic parable started in an unlikely place: a desk at San Francisco State. Three years ago, Hafernik returned from a field trip with a hungry praying mantis, so he scrounged for insects for it to eat. He found some bees under the light fixtures outside his classroom at Hensill Hall, and stuck them in a vial.

“But being an absent-minded professor,” he joked, “I left them in a vial on my desk and forgot about them.”

When he looked at the vial again — a week or so later — there was a startling sight: the dead bees were surrounded by small brown fly pupae.

“I knew that was unusual,” he said. “I knew that a parasitic fly was feeding on them.”

The fly’s identity — Apocephalus borealis — was revealed through a DNA test. The same fly is known to infect wasps and bumblebees.

Ivers and fellow grad student Andrew Core gained permission from Bay Area beekeepers to set up traps at the hives, then caught 20 to 50 so-called worker bees en route to find food.

Infected bees were found in San Francisco, Oakland, Orinda, Walnut Creek, Concord, El Cerrito, El Sobrante, Benicia, San Rafael, Mill Valley and Larkspur. They were not found in hives in Los Gatos, Saratoga, San Jose or Mount Hamilton.

The parasitic flies even engage in mind control. Somehow they’re able to hijack the bee’s normal daytime behavior, turning it into a nocturnal creature. Seven days after death, little larvae emerge from the bee.

The casualties are hard on a hive in two different ways. Not only does it lose important workers — but when these foragers are gone, younger bees inside the hive are forced to take their place. The entire labor structure of the hive goes awry.

“As you lose more and more workers, there’s a tipping point, which could lead to collapse,” he said.

Bees from the infected hives are often infected with a virus and a fungus — suggesting the fly might be a vector for these pathogens.

There are other gruesome examples in the insect world of exploitation.

An Asian wasp stings a cockroach in the brain and injects venom that controls where the roach walks. Then it lays its egg on the roach, and its larvae eat it alive.

And there’s an Amazonian nematode that, once inside an ant, turns the insect’s abdomen the same bright hue as a tasty berry. The ant is eaten by birds, who spread baby nematodes through their droppings.

While San Francisco State researchers are far from discovering a treatment for bees, the next step is to expand their geographic search for infected hives.

Already, Hafernik has noticed a colony in the walls of his San Francisco house. “At night, they bounce against the windows while my wife and I are at the dinner table,” he said brightly.

And they’ll deploy a range of identification tools to better understand the freeloading fly. Next spring, they will glue tiny radio-frequency devices — smaller than the head of a pin — to the backs of bees, then track their travels. Once sick, do they re-enter the hive, infecting others?

“We don’t know how big a player this is” in collapsing colonies, he said. “It could be a really important one.”

Contact Lisa M. Krieger at 408-920-5565.