The high court in London, however, ruled there was nothing to stop NHS England paying for the drug, which was recommended for preventative use by the European Medicines Agency last month.
The National AIDS Trust had brought the legal case, arguing that PrEP was a potential game-changer and was urgently needed in the UK, where more than 4,000 people acquire HIV annually.
Use of of PrEP is rising fast in the United States, where tens of thousands of people have filled prescriptions for Truvada to prevent infection.
Despite the win for the British AIDS campaigners, there is no guarantee that PrEP will now get automatic NHS funding.
NHS England said it planned to appeal the decision and, even it it loses again, PrEP would be have to be assessed against other priorities.
"Of course, this does not imply that PrEP - at what could be a cost of 10-20 million pounds ($13-26 million) a year - would actually succeed as a candidate for funding when ranked against other interventions," said Jonathan Fielden, NHS England's head of specialised commissioning.
"But in those circumstances, Gilead ... will be asked to submit better prices, which would clearly affect the likelihood that their drug could be commissioned."
Follow CNBC International on Twitter and Facebook.