Judge Alistair McCreath told Southwark Crown Court he thought witness Mazher Mahmood, a reporter with the Sun on Sunday newspaper who is known as the “Fake Sheikh”, had lied in giving evidence.
Ms Contostavlos had denied the allegations against her.
The judge told the jury the case “cannot go any further” because there were “strong grounds to believe” that Mr Mahmood had “lied” at a hearing before the trial started.
He has been “suspended pending an internal investigation” his employer said.
Mr Mahmood claimed Ms Contostavlos, 26, had brokered a deal through her friend, rapper Mike “GLC” Coombs, to supply Class A drugs.
Reading from a statement outside the court, Ms Contostavlos said: “Let me be perfectly clear, I have never dealt drugs and never been involved in taking or dealing cocaine.
“This whole case was a horrific and disgusting entrapment by Mazher Mahmood and the Sun on Sunday newspaper.
“Mahmood has now been exposed by my lawyers openly lying to the judge and jury. These lies were told to stop crucial evidence going before the jury. This evidence showed that I told Mahmood’s long-standing driver that I disapproved of drugs, which is the truth.
“It is clear that the driver was pressurised to change his statement to strengthen Mahmood’s evidence and to damage mine. Thankfully, the lies have been uncovered and justice has been done.”
She added: “This case only happened because Mahmood and his team tricked me into believing I was auditioning for a major movie.
“They targeted me at a time when things were going badly for me and they had no mercy. Mahmood got me and my team completely intoxicated and persuaded me to act the part of a bad, rough, ghetto girl.
“They recorded this and produced it as evidence when I thought it was an audition. It was a terrible thing to do. We have now succeeded in exposing the real culprits, and, most importantly, the real liar.
“I urge both police and [Sun on Sunday owners] News UK to investigate Mazher Mahmood and his team and to put an end to his deceit in pursuit of sensational stories.”
She concluded: “I have not been able to work for a year, and am now looking forward to resuming my career.”
After reading her statement, the singer ducked into a waiting taxi as she was surrounded by photographers.
Immediately on hearing the case had been thrown out, Ms Contostavlos had been unable to contain her joy and wept as she hugged friends and family in the corridor outside Courtroom Two at Southwark.
The former N-Dubz singer was also keen to inform friends of events, as one of the first things she did on leaving the dock was make a phone call.
Mike Coombs, who had earlier pleaded guilty to supplying cocaine, also cried and hugged Ms Contostavlos outside court.
The Met Police said it had not yet made a decision about what was going to happen with regards to Mazher Mahmood.
A spokesman said for the Sun on Sunday said: “We are very disappointed with this outcome, but do believe the original investigation was conducted within the bounds of the law and the industry’s code. This was demonstrated by the CPS decision to prosecute.
“The Sun, of course, takes the judge’s remarks very seriously. Mr Mahmood has been suspended pending an immediate internal investigation.”