“Magic” mushrooms seem to have passed their genes for mind-altering substances around among distant species as a survival mechanism: By making fungus-eating insects “trip,” the bugs become less hungry — and less likely to feast on mushrooms.

That’s the upshot of a paper published Feb. 27 in the journal Evolution Letters by a team of biologists at The Ohio State University and the University of Tennessee.

The researchers studied a group of mushrooms that all produce psilocybin — the chemical agent that causes altered states of consciousness in human beings — but aren’t closely related. The scientists found that the clusters of genes that caused the ‘shrooms to fill themselves with psilocybin were very similar to one another, more similar even than clusters of genes found in closely related species of mushrooms.

That’s a sign, the researchers wrote, that the genes weren’t inherited from a common ancestor, but instead were passed directly between distant species in a phenomenon known as “horizontal gene transfer” or HGT.

HGT isn’t really one process, as the biologist Alita Burmeister explained in the journal Evolution, Medicine and Public Health in 2015. Instead, it’s the term for a group of more or less well-understood processes — like viruses picking up genes from one species and dropping them in another — that can cause groups of genes to jump between species.

However, HGT is believed to be pretty uncommon in complex, mushroom-forming fungi, turning up much more often in single-celled organisms.

When a horizontally transferred gene takes hold and spreads after landing in a new species, the paper’s authors wrote, scientists believe that’s a sign that the gene offered a solution to some crisis the organism’s old genetic code couldn’t solve on its own.

The researchers suggested — but didn’t claim to prove — that the crisis in this case was droves of insects feasting on the defenseless mushrooms. Most of the species the scientists studied grew on animal dung and rotting wood — insect-rich environments (and environments full of opportunities to perform HGT). Psilocybin, the scientists wrote, might suppress insects’ appetites or otherwise induce the bugs to stop munching quite so much mush’.