Transport bosses were right to ban a Christian group's bus advert suggesting gay people could be helped to change their sexuality, it has been ruled.
The High Court ruled Transport for London's process in introducing the ban "was procedurally unfair".
But it ruled TfL was acting lawfully in banning the Core Issues Trust's proposed advert because it would "cause grave offence" to those who were gay.
The posters read: "Not Gay! Ex-Gay, Post-Gay and Proud. Get over it!"
They were a response to a bus poster campaign by gay rights group Stonewall, which carried the message: "Some people are gay. Get over it!"
The High Court's ruling also said the Stonewall advertisement was "highly offensive to fundamentalist Christians and other religious groups whose religious belief is that homosexuality is contrary to God's teachings".
A judge ruled Boris Johnson did not abuse his position as chairman of TfL when he imposed the ban.
The Core Issues Trust said the London mayor was "politically driven" when he intervened to block the ad, which suggested gay people could be helped to "move out of homosexuality".
Mr Johnson condemned the "gay cure" advert as "offensive to gays" and said it could lead to retaliation against the wider Christian community.
Mrs Justice Lang ruled TfL's process in introducing the ban "was procedurally unfair, in breach of its own procedures and demonstrated a failure to consider the relevant issues".
But that was outweighed by factors against allowing the ad, including that it would "cause grave offence" to those who were gay and was perceived as homophobic, "thus increasing the risk of prejudice and homophobic attacks", said the judge.
TfL refused to carry the Core Issues Trust advert on the grounds it was "likely to cause widespread or serious offence to members of the public", and it contained "images or messages which relate to matters of public controversy and sensitivity".
TfL's lawyers argued Article 10 did not entitle the trust to advertise "offensive material".
They said the ban was justified by the need to protect public morals and the right of homosexuals under Article 8 of the convention to respect for their dignity and private lives.
The judge revealed her concern over the issues raised by the case by giving Core Issues permission to appeal to the Court of Appeal.
Mrs Justice Lang said, although she did not think an appeal would succeed, there were "compelling reasons" to allow one to go ahead.
She said the case "concerns interference with the right to freedom of expression which is a matter of such fundamental importance that it merits consideration by the appellant court".
Following the ruling, a TfL spokesperson said: "The advertisement clearly breached our advertising policy as it contained a controversial message and was likely to cause widespread offence to the public.
"This was borne out by the hugely negative public reaction the advertisement generated, including on social media and newspaper websites.
"We are taking steps to address the Judge's comments regarding our internal processes."
A Core Issues Trust spokesman said: "We are grateful for the opportunity to make an appeal and the recognition of the issues around freedom of speech and conscience.
"We are particularly concerned about the fact ex-gay minorities are not recognised in the legislation of the Equality Act 2010."
The Christian Legal Centre (CLC), which is supporting the Core Issues Trust, said: "Some people choose not to act on same-sex attraction. They should not be ostracised for doing so but helped, if that is what they choose."
Gay rights group Stonewall chief Ben Summerskill said: "Many people will be pleased by today's decision.
"In a city where over half of gay young people face bullying at school, and where tens of thousands of gay people are subjected to hate crimes every year just because of the way they were born, it's perfectly proper for a mayor to object to the use of such advertising in an iconic public setting."