London mayor Boris Johnson is to face a new High Court probe over a controversial ban on a bus advert suggesting gays can be helped to "move out of homosexuality".

The Core Issues Trust charity accuses the mayor of unlawfully using his position as chairman of Transport for London (TfL) to obtain the 2012 ban of the Christian ad to secure the gay vote while campaigning for re-election.

The High Court initially rejected the allegations, but today the Court of Appeal said fresh evidence meant there must be a further investigation by High Court judge Mrs Justice Lang as to whether the mayor had acted "for an improper purpose".

Lord Dyson, Master of the Rolls, sitting with two other judges, said an email which has come to light "unequivocally states that the mayor 'instructed' TfL to pull the advertisement" just before the 2012 mayoral elections.

The judge said the need for examination of the role of the mayor was even greater because the email, sent on April 12 2012, "shows that the mayor's office contacted the Guardian (newspaper) immediately, apparently in order to make political capital out of the story".

Arrangements were also been made for the mayor to appear on April 13, the following day, at hustings organised by Stonewall.

Lord Dyson, sitting with Lord Justice Briggs and Lord Justice Christopher Clarke, said: "This is a most unsatisfactory state of affairs."

The judge said it was "surprising" that TfL had not obtained witness statements from the mayor and others to explain the email.

But even if the 2012 ban is overturned, the court said it would be lawful for TfL to impose a fresh order - provided it is properly made - on the grounds that the Core Issues ad is likely to cause widespread or serious offence.

The disputed ad is designed for the sides of the capital's buses and reads: ''Not Gay! Ex-Gay, Post-Gay and Proud. Get over it!''

It was a response to a bus poster campaign by gay rights group Stonewall, which carried the message: ''Some people are gay. Get over it!''

Mr Johnson said the Core Issues ad was ''offensive to gays'' and could lead to retaliation against the wider Christian community.

High Court judge Mrs Justice Lang rejected the claim that the ban was unlawful last March.

She said: ''In my view, such unlawfulness has not been established on the evidence.''

But today Lord Dyson said it was not possible to reach a conclusion on the question without a further hearing.

He said in a written ruling: "I would, therefore, remit the case for the judge (Mrs Justice Lang) to reconsider this question in the light of fresh evidence and in the light of any further material that emerges as a result of the directions that she may give."

If after reconsideration "the judge decides that the decision was not instructed by the mayor and not made for an improper purpose, then her decision (upholding the ban) will stand".

But if it was legally flawed by the mayor's intervention it would have to be quashed.

Core Issues Trust and its linked body the Christian Legal Centre hailed today's ruling as a "significant victory" and praised the court for carrying out "an historic duty of holding politicians to account and refusing to tolerate non-transparent behaviour".

Dr Mike Davidson, who leads the Trust, said he is now writing to the Mayor demanding that all emails "current and potentially deleted" linked to the ad ban be made available to his lawyers.

A TfL spokewoman said: "We welcome the Court of Appeal's judgment that a decision not to run the Core Issues Trust's advertisement was justified.

"The advertisement breached our advertising policy and caused 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 shall be pleased to comply with any requirements the court may have for the supply of further evidence."

Mr Johnson's official spokesman said: "The mayor is pleased that the court has upheld TfL's right to ban the Core Issues Trust advert.

"He agreed with TfL's ban at the time and will continue to support the banning of adverts that breach advertising policy and cause widespread public offence, as this advert clearly did."

Paul Diamond, appearing for the Trust, had told the appeal judges that at the heart of the case was the "ironical" situation in modern British society where ancient Biblical scriptures, which played an important role in forming the nation's morals, were now in danger of containing views which could no longer be expressed "in a land with a reputation for free speech".

The Trust has accused gay and lesbian rights activists of seeking to be the new "moral enforcers" and says it is Christian religious conservatives who now need protection for their right to express dissent against "the new orthodoxy".