The mayor of London, Boris Johnson, intervened to prevent a Christian advertising campaign from promoting the idea that gay people can be converted to heterosexuality.

Just days before the posters were due to appear on buses in the capital, Johnson ordered his transport chiefs to pull the adverts booked by two conservative Anglican groups following outrage among gay campaigners and politicians saying that they were homophobic. The adverts were booked on behalf of the Core Issues Trust whose leader, Mike Davidson, believes "homoerotic behaviour is sinful".

His charity funds "reparative therapy" for gay Christians, which it claims can "develop their heterosexual potential". The campaign was also backed by Anglican Mainstream, a worldwide orthodox Anglican group whose supporters have equated homosexuality with alcoholism. The advert was due to say: "Not gay! Post-gay, ex-gay and proud. Get over it!"

Johnson, who contacted the Guardian to announce he was stopping the adverts within two hours of their contents becoming public, said: "London is one of the most tolerant cities in the world and intolerant of intolerance. It is clearly offensive to suggest that being gay is an illness that someone recovers from and I am not prepared to have that suggestion driven around London on our buses."

His main rival in next month's mayoral election, Ken Livingstone, said Johnson should never have allowed the adverts to be booked. "London is going backwards under a Tory leadership that should have made these advertisements impossible.

"They promote a falsehood, the homophobic idea of 'therapy' to change the sexual orientation of lesbians and gay men."

The Christian groups insisted the advert had been cleared with Transport for London (TfL), which is chaired by the mayor. Davidson said: "I didn't realise censorship was in place. We went through the correct channels and we were encouraged by the bus company to go through their procedures. They okayed it and now it has been pulled."

CBS Outdoor, the media company that sells the bus advertising sites, said the ad had been passed for display by the Committee of Advertising Practice. It is understood TfL was due to make around £10,000 for allowing the adverts to run on about two dozen buses across five routes.

The campaign was an explicit attempt to hit back at the gay rights group Stonewall, which as part of its lobbying for the extension of marriage to gay couples is running its own bus adverts saying: "Some people are gay. Get over it." The Christian groups used the same black, red and white colour scheme as Stonewall and in a statement announcing the campaign accused it of promoting the "false idea that there is indisputable scientific evidence that people are born gay".

The gay ex-vicar, Labour MP and former minister Chris Bryant, said the advert was cruel for promoting the idea that you could become "ex-gay" and he said it would particularly hurt teenagers struggling to come to terms with their sexuality.

"The emotional damage that is done to the individuals who try to suppress their sexuality, the women they marry and the children they might have is immeasurable," he said. "Most sane Christians believe that homosexuality is not a lifestyle or a choice but is a fact to be discovered or not. The pretence that homosexuality is something you can be weaned off in some way is a fundamental misunderstanding of the nature of creation."

Ben Summerskill, the chief executive of Stonewall, said the adverts were "clearly homophobic" and added: "The only reason some gay people might want to stop being gay is because of the prejudice of the people who are publishing the ad.

"The promotion of this voodoo therapy is hugely irresponsible given the damage that it appears to do to some people."

Both men said the advert should not be banned, however, because they believed in freedom of speech.

Attempts to "treat" or alter sexual orientation have been strongly condemned by leading medical organisations. The Royal College of Psychiatrists has warned that "so-called treatments of homosexuality create a setting in which prejudice and discrimination flourish" and concluded in 2010: "There is no sound evidence that sexual orientation can be changed."

The British Medical Association has also attacked "conversion therapy", a related field to reparation therapy, passing a motion asserting that it is "discredited and harmful to those 'treated' ".

The Rev Lynda Rose, a spokesperson for the UK branch of Anglican Mainstream, said her group adhered to scripture that all fornication outside marriage is prohibited and believed that homosexuals were "not being fully the people God intended us to be". She said therapies endorsed by Anglican Mainstream and Core Issues were not coercive and were appropriate for people who wanted to change their sexual attractions, for example if they were married and worried about the impact of a "gay lifestyle" on their children.

The decision to pull the adverts is being seen as a potential boost for conservative Christian organisations attempting to become more politically active in the UK. "Banning this is usually a fairly good way to encourage a sense that people are being marginalised and persecuted," said Simon Barrow, co-founder of the Ekklesia thinktank which has tracked the progress of what it calls aggressive conservative Christianity. "It could be part of a developing tactic to draw attention to themselves and a way of using victimhood to galvanise sympathy and support."

Brian Paddick, the Liberal Democrat mayoral candidate, said: "From personal experience as a gay Christian, I can tell you that it's much better to be out than in. We should be celebrating the diversity for which London is known, not denigrating it.

Revelations about the adverts came as Johnson was due to appear at a hustings organised by Stonewall on Saturday.

• The original version of this article stated that 'the ad had been passed for display by the Committee of Advertising Practice and it complied with Advertising Standards Authority (ASA) guidelines'.

In fact the ASA does not pre-clear adverts and had nothing to do with the decision to pass the advert. The article has been amended to reflect this and to also remove a subsequent quote misattributed to the ASA.