A judge has demanded an inquiry "at the highest level" after a man was cleared of raping a woman after key evidence which proved his innocence was finally disclosed by police.

The trial of Liam Allan dramatically collapsed after he spent two years on bail accused of six counts of rape and six counts of sexual assault by a woman who told police she does not enjoy sex.

Allen, 22, denied the accusations and claimed the woman was making the malicious claims because he was due to attend university and would not be able to see her anymore.

After spending three days in the dock, all charges against him were dropped after the prosecution made a shock announcement that the woman's phone records which police previously refused to hand over were finally disclosed and proved he was not guilty.

Allan's lawyers had frequently been denied access to the woman's phone records by police, who believed it would offer nothing of interest for the prosecution or defence. However, newly appointed prosecution barrister Jerry Hayes demanded they be handed over for the trial.

It was then revealed that police had a computer disk containing copies of more than 40,000 messages, proving the woman frequently asked for "casual sex" from Allen. The messages also revealed she discussed how much she enjoyed having sex with him and discussed her fantasies of being raped and having violent sex, reports the Times.

Hayes told Croydon Crown Court he would offer no evidence at the trial. He said: "I would like to apologise to Liam Allan. There was a terrible failure in disclosure which was inexcusable.

"There could have been a very serious miscarriage of justice, which could have led to a very significant period of imprisonment and life on the sex offenders register. It appears the [police] officer in the case has not reviewed the disk, which is quite appalling."

Allan faced up to 10 years in jail had he been found guilty of the charges against him.

Judge Peter Gower has ordered an investigation to be carried out by the Met Police as well as the Crown Prosecution Service (CPS). He added: "Something has gone very, very wrong in the way this case was investigated and brought to court."

Following the collapse of the trial, a Met police spokesperson said: "We are aware of this case being dismissed from court and are carrying out an urgent assessment to establish the circumstances which led to this action being taken.

"We are working closely with the Crown Prosecution Service and keeping in close contact with the victim whilst this process takes place."

A CPS spokesperson added: "A charge can only be brought if a prosecutor is satisfied that both stages of the Full Code test in the Code for Crown Prosecutors are met, that is, that there is sufficient evidence to provide a realistic prospect of conviction and that a prosecution is required in the public interest.

"All prosecutions are kept under continuous review and prosecutors are required to take account of any change in circumstances as the case develops.

"In November 2017, the police provided more material in the case of Liam Allan. Upon a review of that material, it was decided that there was no longer a realistic prospect of conviction.

"Therefore we offered no evidence in the case against Liam Allan at a hearing on December 14 2017.

"We will now be conducting a management review together with the Metropolitan Police to examine the way in which this case was handled."