They then put an undercover agent through court with false charges - later claiming they did so with the blessing of Chief District Court Judge Russell Johnson.
Documents released by the High Court show testimony from police undercover programme boss Detective Senior Sergeant Warren Olsson in August about an earlier case said to show a precedent for colluding with a judge during an investigation.
Mr Olsson said an undercover officer from the 2002 Operation Kansas had a judge's blessing to go through the court process under a fake name on charges which were later dropped.
Mr Olsson said "the permission of a District Court judge" meant the agent went before the court under an assumed name "until after the operation was finished whereby the charges were withdrawn".
Mr Olsson said he had "a working knowledge" of Operation Kansas as head of the undercover programme and National Co-ordinator of Gang Intelligence.
But details released by the High Court in Wellington showed an alternative version of events.
A 2003 signed statement from then-Wanganui court manager Marcus Vettise stated Judge Mike Crosbie would not discuss the issue with the senior police officer who had sought a private meeting.
Mr Vettise said he escorted Detective Senior Sergeant Warren Smith to the judge's chambers. He said it became clear "the operation was at risk due to the operative's identity being revealed and that police were considering several options".
Mr Vettise said the senior detective spoke of police considering laying a charge against the undercover agent.
He said "I distinctly remember at that point the judge holding up his hand, motioning for Detective Smith to stop and saying words to the effect 'I don't want to know about any of this' or 'I don't want to know about that'."
He said the meeting ended at that point.
The details were released by Justice Forrest Miller who said there was a strong public interest in matters relating to the performance of the police and the courts.
Justice Miller said he accepted it might lead to criticism of individual police but "the police will have the opportunity to comment on it".
Police national media manager Grant Ogilvie said police would not comment because an appeal on the High Court decision had been made.
Officers involved in the Red Devils operation face possible disciplinary or criminal charges over their actions.
The operation was overseen by the Organised and Financial Crime Agency's Detective Inspector Grant Wormald, who also ran the operation into Kim Dotcom.
Mistakes in that operation have led to a police inquiry into illegal spying by the Government Communications Security Bureau.
Steve Rollo, lawyer for some of the men arrested in the operation, said the Red Devils case raised serious issues for police.
He said no judge was able to give police permission to "commit criminal offences".
"Quite how the police have arrived at a point where their leadership think it's appropriate to try and cosy up to judges behind closed doors in this fashion is beyond me.
"If that kind of thinking sets in across the organisation then we're all in deep trouble."