The difference between psychedelic mushrooms and regular mushrooms is that the former contains a brain-altering compound that can cause hallucinations.

But how did these so-called magic mushrooms develop their "magical" properties? And for what purpose?

According to researchers from the Ohio State University in the US, psychedelic mushrooms evolved to contain psilocybin - the ingredient responsible for causing hallucinations - as a way to fend off insects.

The team identified a cluster of five genes psychedelic mushrooms have in common after examining three species of magic mushrooms and several related fungi species that don't cause hallucinations.

The scientists attribute this to a phenomenon called horizontal gene transfer, where genetic material "hops" from one species to another in response to stressors or opportunities in the environment.

The genes responsible for making psilocybin appear may have been exchanged in an environment with a lot of fungus-eating insects, the scientists said.

They believe these seemingly unrelated mushroom species have the same genetic protection because they happened to grow in same insect-rich mediums such as animal faeces and rotten wood.

Jason Slot, an assistant professor of fungal evolutionary genomics at the Ohio State University, added: "We speculate that mushrooms evolved to be hallucinogenic because it lowered the chances of the fungi getting eaten by insects.

"The psilocybin probably doesn't just poison predators or taste bad. These mushrooms are altering the insect's mind - if they have minds - to meet their own needs."

Video Loading

The researchers believe their work could open scientific doors to studies of new treatments for neurological diseases such as Alzheimer's.

Psilocybin has previously been studied for the treatment of mental disorders, including depression, addiction and certain types of anxiety.

The study is published in the journal Evolution Letters.