The Court of Appeal has ruled that the NHS in England has the power to fund a drug which prevents HIV infection in people at high risk of the virus.
NHS England had previously said that local authorities should provide the pre-exposure prophylaxis drug - known as Prep - because they are responsible for preventative health.
But the court insisted this fell within the remit of the NHS.
An estimated 14,000 people would be eligible for Prep in England.
Campaigners and the Local Government Association, which represents local authorities, said they were delighted by the decision.
NHS England said the judgment confirmed that it had the ability, but not the obligation, to fund Prep.
An NHS spokesman said it would now formally consider whether to fund the drug.
"Second, we will discuss with local authorities how NHS-funded Prep medication could be administered by the sexual health teams they commission.
"Third, we will immediately ask the drug manufacturer to reconsider its currently proposed excessively high pricing, and will also explore options for using generics."
In August, the High Court told NHS England it could fund the drug because it was wrong to classify Prep as preventative, given that it acts in the body to treat infection.
This came after a successful challenge by the National Aids Trust (NAT) and other campaigners.
Deborah Gold, chief executive of NAT, said they were delighted that the Court of Appeal had confirmed the earlier judgement.
"HIV is a critical issue in the UK where over 4,000 people acquire HIV every year.
"Prep works, it saves money, and most importantly it has the power to prevent HIV acquisition for thousands of people, at the same time as beginning to end the HIV epidemic.
"This judgement brings that possibility one step closer."
She said she hoped NHS England would now make "a balanced and evidence-based decision on Prep".
Clarity of roles
Izzi Seccombe, chairman of the Local Government Association's community wellbeing board, said treatment with Prep was clearly part of NHS England's commissioning powers.
"We now hope this decision will provide much-needed clarity around the roles of councils and the NHS on prevention services.
She added: "It is time for NHS England to stop delaying and finally determine whether to commission this treatment, which could greatly reduce the risk of HIV infection."
What does Prep do?
Pre-exposure prophylaxis (or Prep for short) is a small, blue pill.
The pill works by protecting cells in the body and disabling the virus to stop it multiplying - should it enter the body.
Taking it once a day has been shown to reduce the risk of HIV infection by 86%.
It is currently used in the US, Canada, Australia and France to help protect gay men at the highest risk of contracting HIV.
Living with HIV
There are more than 100,000 people living with HIV in the UK and, statistically, gay men are the most at-risk group.
The average HIV prevalence in the UK is 2.3 per 1,000 population. However for gay men the rate jumps to 48.7 per 1,000.
Black African women are the second most at-risk group with a prevalence rate of 43.7 per 1,000.
Latest figures show there were 6,151 new diagnoses made in 2014, up from 6,032 the previous year, according to Public Health England.