Aids campaigners are celebrating a watershed victory after the high court ruled that NHS England can pay for “game-changer” drugs that prevent people being infected with HIV by their partners.

But NHS England made it clear that the fight to get PrEP – pre-exposure prophylaxis – to everyone at risk is far from over. Not only will it appeal against the judgment, but it will weigh up the cost of PrEp – which could be £10m – £20m a year – against other calls on NHS funding for specialised services. It will also put pressure on the pharmaceutical companies manufacturing the drugs to drop their prices.

The health secretary, Jeremy Hunt, has already asked Nice – the National Institute for Health and Care Excellence – to consider the cost-effectiveness of PrEP. Trials have shown the once-a-day pill is highly effective in protecting gay men whose partners are HIV positive. But the cost of the pill, called Truvada, is high.

Condoms are cheap, but among some high-risk populations they are not used consistently. About 4,000 more people acquire HIV in the UK every year. The average cost of a lifetime of treating each one is put at about £360,000.

The National Aids Trust brought the high court case following anger and consternation among campaigners after NHS England said it would not fund PrEP because it did not have the power to do so. It argued that it was the role of local authorities, which have been given control of public health measures including reducing smoking and family planning, as well as HIV prevention. Local authorities said they did not have the money to pay.

Mr Justice Green in the high court said NHS England had erred and that both it and the local authorities were able to fund the drugs if they so chose.

“No one doubts that preventative medicine makes powerful sense,” he said in his judgment. “But one governmental body says it has no power to provide the service and the local authorities say that they have no money. The clamant [the National Aids Trust] is caught between the two and the potential victims of this disagreement are those who will contract HIV/Aids but who would not were the preventative policy to be fully implemented.”

Deborah Gold, the chief executive of NAT, said: “This is fantastic news. It is vindication for the many people who were let down when NHS England absolved itself of responsibility for PrEP. The judgment has confirmed our view – that it is perfectly lawful for NHS England to commission PrEP. Now NHS England must do just that.”

NAT said, however, it was “enormously disappointing” that NHS England intended to appeal.

NHS England has said it will put aside money to fund PrEP in case it loses in the court of appeal. It will ask Gilead, which makes Truvada, to submit its “best and final price” so the cost of PrEP can be compared with the cost of other calls on NHS specialised funding. It will be competing with drugs for a number of other diseases, including one for children with cystic fibrosis and a form of stem cell transplantation.

Dr Jonathan Fielden, NHS England’s director of specialised commissioning and deputy national medical director, said they were setting the ball rolling so PrEP can be considered for funding following the high court ruling.

“Of course, this does not imply that PrEP – at what could be a cost of £10m-20m a year – would actually succeed as a candidate for funding when ranked against other interventions. But in those circumstances, Gilead – the pharmaceutical company marketing the PrEP drug Truvada – will be asked to submit better prices, which would clearly affect the likelihood that their drug could be commissioned,” he said.

Campaigners say that while the majority of gay men use condoms to prevent being infected with HIV, there is also an “ethical duty” to provide PrEP to those who do not. They believe the drug would provide an additional defence against HIV – and would not be used simply as an alternative to safe sex.

It comes after the results of a trial, published in February 2015, suggested that rates of HIV infection could be slashed by treating gay men with the anti-viral drug when they are healthy.

Dr Michael Brady, the medical director at the HIV/Aids charity Terrence Higgins Trust, welcomed the findings and described the drug as a game-changer.

He said PrEP offered another line of defence against HIV, alongside condoms and regular testing. Brady said: “It is not a vaccine and it won’t be for everyone, but, once approved, we expect it to significantly increase the momentum in our fight against the virus.

“We urge the government, NHS England and local authorities to make PrEP a key priority in the fight against HIV.”