Beneath the soil, cicadas wait — as long as 17 years — until the right temperature beckons them to the surface. At once, they emerge, like zombies rising from graves. They greet the sun, preparing to molt into adults in coming weeks and then fly off to mate.

Such is a cicada’s simple life — unless it’s been infected.

Massospora, a parasitic fungus, has lurked just below the surface, awaiting the cicada’s exit. When a nymph digs through infected soil, fungal spores cling to its body. As the cicada matures, massospora multiplies, digesting the insect’s insides, castrating it and replacing its rear end with a chalky white plug of spores.

The cicada buzzes on, seemingly unaware it’s a mushroom’s moving minion. It flies, attempting to mate with unusual vigor. Some males even mimic females to attract and spread their spores to male partners — the more infected, the better. And as their hijacked bodies copulate, spores sprinkle to the earth and massospora spreads.

“This really has all the elements of a sci-fi horror story,” Matthew Kasson, a mycologist at West Virginia University, said. “How does an organism function even though two-thirds of their body is no longer theirs?”