The trial of Tulisa Contostavlos over drugs allegations has collapsed.

The singer was accused of boasting that she could "sort out" cocaine for a journalist and put him in touch with her rapper friend Mike GLC, who supplied the Class A drug.

Undercover reporter Mazher Mahmood, dubbed the "Fake Sheikh", posed as a wealthy film producer called Samir Khan when he met the former X Factor judge at a string of luxury hotels and restaurants, jurors at London's Southwark Crown Court heard.

Contostavlos vehemently denied brokering the deal, which was exposed in The Sun on Sunday newspaper last June.

Today judge Alistair McCreath told the jury that the case "cannot go any further" because there were "strong grounds to believe" that Mahmood had "lied" at a hearing before the trial started.

A Sun spokesman 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."

After hearing the news, Contostavlos urged police to investigate Mahmood and "put an end to his deceits".

The 26-year-old star smiled broadly in the dock as the jury was formally discharged from trying the case.

Contostavlos appeared ecstatic, punching the air as she left the dock before crying as she hugged supporters including her PA, Gareth Varey, shortly after the case against her was thrown out.

Mike GLC – whose real name is Michael Coombs – pleaded guilty before the start of the trial to supplying half an ounce (13.9g) of cocaine but he also walked free after judge said the case cannot proceed against him.

The 36-year-old also wept as he hugged defence barrister Jeremy Dein QC.

Explaining his decision to halt the case to the jury, the judge said: "Occasionally – very rarely – circumstances may arise in which a court has to say that whatever apparent merits a prosecution may have, the court cannot allow the prosecution case to be taken forward to trial."

He said the situation arose from a "fundamental principle" that the court "cannot allow itself to be party to improper conduct".

The judge went on: "Where there has been some aspect of the investigation or prosecution of a crime which is tainted in some way by serious misconduct to the point that the integrity of the court would be compromised by allowing the trial to go ahead, in that sense the court would be seen to be sanctioning or colluding in that sort of behaviour, then the court has no alternative but to say, 'this case must go no further'."

It can now be reported that before the trial began, defence counsel argued that the case should be "stayed" – meaning thrown out – but their application was turned down.

But giving his ruling today, the judge said "matters have moved on since then".

The court heard the collapse of the case hinged on evidence given by Mahmood about a statement given to police by a driver called Alan Smith who picked up Contostavlos from a hotel in London in May last year.

Smith originally suggested he had heard the star talking disapprovingly about drugs but "changed his mind" after a conversation with the undercover reporter, the court was told.

During a pre-trial hearing Mahmood was asked: "Did you subsequently ask or find out, discuss with Mr Smith anything that was said in the car?"

He replied: "No."

Asked if at any stage he discussed Contostavlos saying she "disapproved" of drugs, he also said no.

But the judge said he gave answers which were "entirely inconsistent" when he gave evidence about the same topic at the trial last week.

Speaking outside the court 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 shows that I told Mahmood's long-standing driver that I disapproved of drugs, which is the truth.

"It is clear that the driver was pressured to change his statement to strengthen Mahmood's evidence and to damage mine.

"Thankfully the lies have been uncovered and justice has been done.

"This case only happened because Mahmood and his team tricked me into believing I was auditioning for a major movie role.

"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 this as evidence when I thought it was an audition. It was a terrible thing to do.

"As my lawyer said at the outset, we have now succeeded in exposing the real culprits and, most importantly, the real liar.

"As someone who has had my life ruined for the last year I strongly believe that this type of entrapment should not be allowed to happen to anyone.

"I urge both the police and News UK to investigate Mazher Mahmood and his team and to put an end to his deceit in pursuit of sensational stories for commercial gain.

"I have not been able to work for a year, and I am now looking forward to resuming my career.

"I will use these experiences to make me stronger. I would like to thank all the people who have supported me through this terrible ordeal, including my fans and, of course, my legal team."