The case against an Oxford University student who had a rape charge "hanging over his head" for two years has been dropped on the eve of his trial.
Oliver Mears had been on bail since his arrest on suspicion of rape and sexual assault in July 2015, when he was 17.
A judge criticised prosecutors' "last-minute" decision to drop the case, made after new evidence emerged last week.
Surrey Police admitted its initial investigation into Mr Mears, now 19, had been flawed.
The chemistry scholar, from Horley, was attending St Hugh's College but suspended his studies amid investigations into the allegations.
He learned this week that prosecutors would offer no evidence against him after a diary which supported his case was uncovered.
At Guildford Crown Court, where the case was formally thrown out, Judge Jonathan Black heard the diary "tips the balance" in favour of the defendant.
Prosecutor Sarah Lindop said it contained previously unseen evidence which was "not of assistance to the prosecution".
Other "third-party" material had also contributed to the decision, she said.
Surrey Police said it is now reviewing all of its rape cases "to ensure that investigations are thorough, timely, effective and compliant with policy and guidelines."
It comes after Scotland Yard said it would review all sex crime investigations where a suspect had been charged, following the collapse of two rape prosecutions in a week.
A file was passed to the Crown Prosecution Service (CPS) in May last year and Mr Mears was charged a month later.
The judge criticised "unnecessary delays" in the case, which Mr Mears and the complainant had "hanging over their heads" for two years.
"Had the investigation been carried out properly in the first instance, [it] would not have led to this position", he said.
Reports had suggested Mr Mears' case was among a number of recent high-profile trials dropped over failure to disclose evidence.
Although there were "some disclosure matters", Ms Lindop said, "this is not a disclosure case per se".
Judge Black demanded the head of the CPS rape and sexual offences unit write to him within 28 days "with a full explanation of what went wrong".
He would then decide whether any action was required.
As Mr Mears' mother left court, she said she was "delighted" at the result.
By Danny Shaw, BBC home affairs correspondent
Oliver Mears wasn't in court to hear the "not guilty" verdicts, but he'll no doubt be immensely relieved - and heartened to know that the judge was critical about how long it had taken to get to that point.
The reasons for the delay remain unclear, despite the prosecutor's explanation in court.
Cases like this aren't straightforward, but why did it take two years for charges to be brought and a further seven months for evidence to emerge that killed off an already finely-balanced prosecution?
This is the fourth time in four weeks that a rape case has collapsed in such circumstances and it is hard to avoid the conclusion that there is something fundamentally wrong with the system.
Surrey Police said the CPS had requested the force provide materials from the complainant's digital media on 5 January 2018.
These were handed over on 15 January, it added.
The force said it "deeply regrets mistakes made in the efficacy of investigations".
A spokesperson admitted there were flaws in the initial investigation, during which the complainant's digital media went unexamined.
Officers did not follow "what we would consider to be a reasonable line of enquiry", they added,
The force has launched an internal review, but said the case was dropped for "a number of reasons", only one of which related to Surrey Police.
A CPS spokesman said "prosecutors were not satisfied there was a realistic prospect of conviction," after an evidence review.
The CPS offered no evidence against both Liam Allan and Isaac Itiary after the late disclosure of evidence that could have assisted the defendants.