Scientists carried out scanning studies which showed how a distracting memory test blocked incoming pain signals.
Volunteers were asked to complete either a hard or easy letter memory task while having a painful level of heat applied to their arms.
While distracted by the harder task, they perceived less pain. This was reflected by lower activity in the spinal cord which could be seen in the functional magnetic resonance imaging scans.
"The results demonstrate this phenomenon is not just a psychological phenomenon, but an active neuronal mechanism reducing the amount of pain signals ascending from the spinal cord to higher-order brain regions," said study leader Dr Christian Sprenger, from the University Medical Centre Hamburg-Eppendorf in Germany.
The findings are reported online in the journal Current Biology.
Giving the volunteers the opioid-blocking drug naloxone reduced the pain-relieving effect of distraction by 40%. This was evidence that endogenous opioids – the brain's natural equivalent of morphine – played an essential role.
"Our findings strengthen the role of cognitive-behavioural therapeutic approaches in the treatment of pain diseases," the researchers wrote.