Researchers analysed data about more than 160,000 people in the UK, of whom 4,353 died from the disease during a 14-year period up until 2008.
They found those who were in psychological distress had a 32 per cent great chance of later dying from cancer.
However they stressed this correlation was not evidence that depression caused cancer.
In fact, it could be the other way around – that having undiagnosed cancer results in changes in the body that make people feel unhappy even if they are unaware they are sick.
One of the researchers, Dr David Batty, of University College London, said: “The results show that compared with people in the least distressed group, death rates in the most distressed group were consistently higher for cancer of the bowel, prostate, pancreas, and oesophagus and for leukaemia.
“Our findings contribute to the evidence that poor mental health might have some predictive capacity for certain physical diseases but we are a long way off from knowing if these relationships are truly causal.”
The findings of the study were published in The BMJ medical journal.
The paper said there was “a suggestion that sub-clinical malignancy [undiagnosed tumours] might have had an impact on mood”.
But it also said there were potential ways that depression could have an effect on cancer.
“Of the biological mechanisms, mood disorders such as depression have been implicated in immune pathways and are known to provoke inflammatory responses,” the paper said.
“Prolonged immune dysregulation can compromise the repair capacity of the exposed cells, potentially contributing to genetic instability and mutations, alterations in DNA repair, and inhibition of apoptosis.
“Immune dysregulation can also lead to a worse prognosis for several carcinomas, including cancer of the colorectum, lung, mesothelium, and stomach.”
William Doan's art tackling mental health
The researchers said that, in conclusion, “our findings add to the growing evidence of an association between psychological distress and physical conditions by characterising new relations with death from selected cancer presentations”.
“The extent to which these associations could be causal requires further testing with alternative study designs,” they added.