A simple blood test could help doctors devise personalised treatments for men with advanced prostate cancer.
The new test, which costs less than £50, can predict which patients are likely to respond to new targeted drugs, and who might be better served by alternative therapies.
It looks for multiple copies of a gene for the androgen receptor, a hormone-sensitive molecule that helps many prostate cancers to grow.
Men with multiple copies of the gene were found to respond much less well to the drugs abiraterone and enzalutamide, both used to treat advanced prostate cancer.
The drugs are given to men whose cancer is no longer responding to traditional hormone therapy and has started to spread.
Lead researcher Dr Gerhardt Attard, from the Centre for Evolution and Cancer at The Institute of Cancer Research, London, said: "Abiraterone and enzalutamide are excellent treatments for advanced prostate cancer and some men can take these drugs for years without seeing a return of their cancer.
"But in other men, these drugs do not work well and the disease rapidly returns. Currently, there is no approved test to help doctors choose whether these are the best treatments for an individual.
"We have developed a robust test that can be used in the clinic to pick out which men with advanced prostate cancer are likely to respond to abiraterone and enzalutamide, and which men might need alternative treatments.
"Our method costs less than £50, is quick to provide results, and can be implemented in hospital laboratories across the NHS. We are now looking to assess our test in prospective clinical trials and would hope it can become part of standard patient care."
For the study, published in the journal Annals of Oncology, scientists took blood samples from patients taking part in three different clinical trials.
In the primary trial of 171 patients, men found to have multiple copies of the androgen receptor gene were four times more likely to die than those who had a negative test result.
Men with multiple copies of the gene from a second group of 94 patients responded to abiraterone and enzalutamide for an eight-fold shorter time than those with only one or two copies.
The androgen receptor was already known to play an important role in cancers becoming resistant to the two drugs.
Dr Iain Frame, director of research at Prostate Cancer UK, which part-funded the study, said: "To stop prostate cancer from being a killer, we need to move away from a one-size-fits-all approach to treatment.
"This test could be a significant step towards that and we'll be watching its development very closely."
Dr Emma Smith, from Cancer Research UK, which also contributed funding, said: "If further studies confirm this test is reliable, it could also help doctors choose better options for men whose prostate cancer is unlikely to respond to standard treatments."
Each year around 41,000 men in the UK are diagnosed with prostate cancer and 11,000 die from the disease.