The messages showed how she had continually messaged Mr Allan for "casual sex", said how much she enjoyed it and discussed fantasies of violent sex and rape, The Times reports.
Outside the court, Mr Allan said he went through "mental torture" over the two year period and relied on the system to uncover evidence that would exonerate him.
When first accused, he turned to a local lawyer he had done work experience with and said he was terrified at the idea of going to prison with sex offenders and worried about what would happen to his mum and flatmates when he was away.
"You are all on your own. I could not talk to my mother about the details of the case because she might have been called as a witness. I couldn't talk with my friends because they might have been called. I felt completely isolated at every stage of the process," he said.
"I can't explain the mental torture of the past two years. ... I feel betrayed by the system which I had believed would do the right thing, the system I want to work in."
SHOCKING MESSAGES DISCOVERED
The life-changing discovery was made at the 11th hour when a new prosecutor, Jerry Hayes, took over the case one day before the trial began and ordered police to hand over records — including a computer disk that contained 40,000 messages.
Mr Allan's lawyers had already sought access to the accusers's telephone records and messages but their requests were denied on the basis there was nothing of interest in them.
Upon discovering the messages, Mr Hayes said he would offer no evidence in court and would like to "apologise" to Mr Allan.
"There was a terrible failure in disclosure which was inexcusable," he said. "There could have been a 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 officer in the case has not reviewed the disk, which is quite appalling."
Speaking later, he said detectives had previously told him the sexual messages were "too personal" to share.
"The defence quickly saw the information blew the prosecution out of the water. If they had not been seen this boy faced 12 years in prison and on the sex offenders' register for life with little chance of appeal. This was a massive miscarriage of justice, which thank heavens was avoided," he told the BBC.
Judge Peter Gower said Mr Allan was not guilty on all charges.
"There is something that has gone wrong and it is a matter that the Crown Prosecution Service (CPS) in my judgment should be considering at the very highest level," he said.
"Mr Allan leaves the courtroom an innocent man without a stain on his character."
Mr Allan's defence lawyer Julia Smart said she also received details about the text messages the night before she was due to cross examine the accuser, and when she told the court of her findings the trial was scrapped.
Mr Allan's mum, Lorraine Allan, 46, said the "current climate" means that many people are treated as "guilty until you can prove you're innocent."
A spokesman for London Metropolitan Police 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 while this process takes place."
The Crown Prosecution Service said they will not conduct a "management review" with the Metropolitian Police to "examine the way in which the case was handled."
Mr Hayes, who is a former Conservative MP wrote in The Times the case marked the most "appalling failure of disclosure I have ever encountered."
"The CPS are under terrible pressure, as are the police. Both work hard but are badly under-resourced.
"Crown court trials only work because of the co-operation and goodwill of advocates and the bench — but time pressures are making this increasingly difficult.