The Court of Appeal has rejected a bid to permit the use of cannabis for the relief of chronic pain.
The appellants were convicted of using or importing cannabis
Three judges ruled against the argument that unlawful conduct could be "excused or justified by the need to avoid a greater evil".
They also said necessity was no defence for using or supplying the drug.
The court dismissed appeals in six cases where people were given fines or suspended sentences after convictions for possessing or importing cannabis.
The court had been told that cannabis was more effective than conventional forms of pain relief and did not have the potentially serious and life-threatening side-effects of alternative treatments.
But the judges ruled that the defences of necessity or duress should be confined to cases where someone committed what would otherwise be an unlawful act to avoid "imminent danger of physical injury".
Barry Quayle, 38, from Market Rasen, Lincolnshire, who had both legs amputated below the knee and suffered pain from damaged tissue and "phantom limb" sensation; Reay Wales, 53, of Ipswich, who has serious bone and pancreas conditions and Graham Kenny, 25, from Shipley, West Yorkshire, who has chronic back pain, all used cannabis for pain relief.
Anthony Taylor, 54, who ran a holistic clinic in King's Cross, north London, attended by around 700 people with HIV/Aids or multiple sclerosis and May Po Lee, 28, also from London, a former employee of Mr Taylor, were convicted of importing the drug.
All had been given either a fine, community service or a suspended community sentence
The judges also ruled that the defence of necessity should not have succeeded in the case of Jeffrey Ditchfield, of North Wales, who was acquitted of possessing the drug with intent to supply it to victims of serious and painful medical conditions.
Despite the decision, Mr Ditchfield cannot now be convicted of the offence.
Lord Justice Mance, sitting with Mr Justice Newman and Mr Justice Fulford, said the general prohibition on cannabis in the 1971 Misuse of Drugs Act showed that any benefits perceived or suggested for individual patients were regarded as outweighed by the disbenefits of allowing its use.
Dr Peter Maguire, Deputy Chair of the British Medical Association's Board of Science said: "BMA research has shown that crude cannabis is unsuitable for medical use because it contains toxic components that are harmful to human health.
"However the potential for cannabis-based medicines to offer effective pain relief can not be overlooked and the BMA would like to see more research in this area."
The judges have left open the possibility of an appeal to the House of Lords, because of the public importance of the issue.