Harry, King Charles' younger son, had brought the action against the government at the High Court in London after the Home Office - the ministry responsible for policing - decided in February 2020 that he would cease to automatically receive personal police security while in the UK.
Harry, along with other senior royals, had received full publicly-funded security protection provided by the state before he stepped back from his royal duties and moved to California with his US wife Meghan in March 2020.
His lawyers told a hearing in December that the decision to take this away subjected him to unlawful, unfair and unjustifiable treatment.
But the government's legal team said the Executive Committee for the Protection of Royalty and Public Figures, known as RAVEC, had not decided Harry should not receive protection but that he should not have it on the same basis.
The High Court agreed, concluding that there had been no unlawfulness in the decision.
"We are pleased that the court has found in favour of the government's position in this case, and we are carefully considering our next steps. It would be inappropriate to comment further," a Home Office spokesperson said, adding the protective security system was "rigorous and proportionate".
Harry's legal representative said in a statement that he intended to bring an appeal.
"The Duke is not asking for preferential treatment, but for a fair and lawful application of RAVEC's own rules, ensuring that he receives the same consideration as others in accordance with RAVEC's own written policy," they said.
Harry was last in the UK earlier this month when he made a whistle-stop visit to see his father after it was revealed the King had been diagnosed with an unspecified form of cancer.
The prince, who has become estranged from his family since his move to the US, has said he hoped Charles' illness could bring the family together.
Whereas the royals usually adopt the mantra of "never complain, never explain," Harry has brought a series of high-profile lawsuits with mixed results so far.
He successfully sued Mirror Group Newspapers over claims of phone-hacking and other unlawful activities, and has been given permission to take similar cases against two other major UK publishers to trial.
But he also withdrew a libel claim against a newspaper relating to a story it had written about his security protection dispute.
Wednesday's ruling marks his second legal defeat on the issue of his security after the High Court ruled against him in a separate challenge against the government's refusal to let him pay for his own police protection.
The prince has often spoken out about his fears for the safety of his family, and has regularly hit out at press intrusion which he blames for the death of his mother Princess Diana.
She was killed when her limousine crashed as it sped away from chasing paparazzi in Paris in 1997.