After swallowing the pill the doctor handed him, 27-year-old Nick Fernandez lay back on the soft brown couch and covered his eyes with a mask.About an hour later, Fernandez told Aeon Magazine, he watched his own funeral.The drug Fernandez had been given was psilocybin, the main psychoactive ingredient in magic mushrooms. He was participating in a New York University trial of the drug in cancer patients with anxiety. And his death-like experience was far from unusual.Other patients who'd been taken through a trip on the drug as part of the trial also remembered witnessing their own deaths. Yet instead of making them feel scared or hurt, the experience imparted the opposite sensation: it gave them a sense of relief.For Fernandez, the funeral itself was unpleasant: It was "a hellish place littered with skulls that smelled of death," he told Aeon Magazine, "where he was in excruciating pain."But when it was over, he felt a deep, enduring feeling of joy and ease. "Something inside me snapped and I experienced a profound psychic shift that made me realise all my anxieties, defences and insecurities werent something to worry about," he said.Other patients in the trial have described similar death-like experiencesDeborah Ames, a breast-cancer survivor in her sixties who asked to be identified by a pseudonym, told New Yorker writer Michael Pollan she remembers traveling all across the world through time and space during her trip, when suddenly she felt herself smack up against the wall of the crematorium where her dead body was being incinerated.Ive died," she recalled thinking to herself, "and now Im going to be cremated."But instead of experiencing pain, Ames remembers feeling peace."The next thing I know, I'm below the ground in this gorgeous forest, deep woods, loamy and brown. There are roots all around me and I'm seeing the trees growing, and I'm part of them. It didnt feel sad or happy, just natural, contented, peaceful. I wasn't gone. I was part of the earth," said Ames.How psychedelics could help alleviate anxiety and depressionScientists still aren't sure exactly why psilocybin or other psychedelic drugs appear to quiet severe anxiety, particularly in people with terminal illnesses like cancer, but the research documenting this tendency extends as far back as the 1960s, before the US government effectively banned psychedelic research.Many of the initial studies into psychedelic drugsparticularly LSDsuggested that they could help alleviate symptoms in people with a wide variety of mental illnesses, including alcoholism and obsessive compulsive disorder, but because these studies were often small (sometimes in only one person) or done without proper controls (which are necessary to help identify whether the drug is having any results), they were classified as mostly inconclusive. In these early experiments, the drugs appeared to quiet the ego or sense of self and help people feel connected with the idea of something bigger than themselves.New research seems to build on these preliminary findings.In one recent study, for example, scientists found that the drug appears to shift the brain's entire organizational framework by sprouting new links across different areas of the brainregions that typically don't communicate with one another.These new connections could help fight depression and anxiety by freeing the mind from loops of negative thought, Paul Expert, the study's lead author and a researcher at Kings College London Center for Neuroimaging Sciences, told Business Insider."The idea is that using psilocybin might help break the loop and change the patterns of functional connectivity in the brain," said Expert.Breaking the loop is critical for patients with terminal illness, since in many of them the idea of death becomes incredibly preoccupying and constant. "Their anxiety about their cancer or their oncoming death was paralyzing their ability to function in the present," Pollan said in a recent radio interview."These people were in pretty desperate straits and this offered a chance at some relief and they tried it. And in many cases it gave them incredible relief," said Pollan.UP NEXT:Here's what happened when a 63-year-old man took shrooms for scienceDON'T MISS:How different drugs change your brainJoin the conversation about this storyNOW WATCH: After losing his son to addiction, a father decided to change the world for the better Click here to read full news..