A judge ruled Boris Johnson did not abuse his position as chairman of Transport for London (TfL) when he imposed the ban.
Mrs Justice Lang, sitting at London’s High Court, ruled that 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 advert, 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.
The decision was a defeat for Core Issues Trust, a Christian charity that said Mr Johnson was “politically driven” when he intervened to block the advert, which suggests that gay people can be helped to “move out of homosexuality”.
The advert posters earmarked for the sides of the capital’s buses read: “Not Gay! Ex-Gay, Post-Gay and Proud. Get over it!”
Mr Johnson condemned the “gay cure” advert as “offensive to gays” and said it could lead to retaliation against the wider Christian community.
The judge revealed her concern over the issues raised by the case by giving Core Issues permission to appeal to the Court of Appeal.
The judge said that, although she did not think an appeal would succeed, there were “compelling reasons” to allow an appeal 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.”
Core Issues, which works with gay people seeking to change their lifestyles, had asked the judge to rule that the charity was unlawfully denied the freedom to express its views on homosexuality.
Paul Diamond, appearing for the charity, said it was imposed in April last year “very close” to the mayoral election on May 3, when Mr Johnson defeated political opponent Ken Livingstone.
Mr Diamond said: “It was clearly a highly-charged issue, and the mayor took credit for the highly, politically-driven decision.
“The mayor was strongly of the view this advertisement should not run.”