Brain imaging experiments have revealed for the first time how ecstasy produces feelings of euphoria in users.

Results of the study at Imperial College London, parts of which were televised in Drugs Live on Channel 4 in 2012, have now been published in the journal Biological Psychiatry.

The findings hint at ways that ecstasy, or MDMA, might be useful in the treatment of anxiety and post-traumatic stress disorder (PTSD).

MDMA has been a popular recreational drug since the 1980s, but there has been little research on which areas of the brain it affects. The new study is the first to use functional magnetic resonance imaging (fMRI) on resting subjects under its influence.

Twenty-five volunteers underwent brain scans on two occasions, one after taking the drug and one after taking a placebo, without knowing which they had been given.

The results show that MDMA decreases activity in the limbic system - a set of structures involved in emotional responses. These effects were stronger in subjects who reported stronger subjective experiences, suggesting that they are related.

Communication between the medial temporal lobe and medial prefrontal cortex, which is involved in emotional control, was reduced. This effect, and the drop in activity in the limbic system, are opposite to patterns seen in patients who suffer from anxiety.

MDMA also increased communication between the amygdala and the hippocampus. Studies on patients with PTSD have found a reduction in communication between these areas.

The project was led by David Nutt, the Edmond J. Safra Professor of Neuropsychopharmacology at Imperial College London, and Professor Val Curran at UCL.

Dr Robin Carhart-Harris from the Department of Medicine at Imperial, who performed the research, said: "We found that MDMA caused reduced blood flow in regions of the brain linked to emotion and memory. These effects may be related to the feelings of euphoria that people experience on the drug."

Professor Nutt added: "The findings suggest possible clinical uses of MDMA in treating anxiety and PTSD, but we need to be careful about drawing too many conclusions from a study in healthy volunteers. We would have to do studies in patients to see if we find the same effects."

MDMA has been investigated as an adjunct to psychotherapy in the treatment of PTSD, with a recent pilot study in the US reporting positive preliminary results.

As part of the Imperial study, the volunteers were asked to recall their favourite and worst memories while inside the scanner. They rated their favourite memories as more vivid, emotionally intense and positive after MDMA than placebo, and they rated their worst memories less negatively. This was reflected in the way that parts of the brain were activated more or less strongly under MDMA. These results were published in the International Journal of Neuropsychopharmacology.

Dr Carhart-Harris said: "In healthy volunteers, MDMA seems to lessen the impact of painful memories. This fits with the idea that it could help patients with PTSD revisit their traumatic experiences in psychotherapy without being overwhelmed by negative emotions, but we need to do studies in PTSD patients to see if the drug affects them in the same way."