The bombshell testimony from Stephen Anderson is the first public account of the twisted culture behind the false arrests in the Brooklyn South and Queens narc squads, which led to the arrests of eight cops and a massive shakeup.

Anderson, testifying under a cooperation agreement with prosecutors, was busted for planting cocaine, a practice known as “flaking,” on four men in a Queens bar in 2008 to help out fellow cop Henry Tavarez, whose buy-and-bust activity had been low.

“Tavarez was … was worried about getting sent back [to patrol] and, you know, the supervisors getting on his case,” he recounted at the corruption trial of Brooklyn South narcotics Detective Jason Arbeeny.

“I had decided to give him [Tavarez] the drugs to help him out so that he could say he had a buy,” Anderson testified last week in Brooklyn Supreme Court.

He made clear he wasn’t about to pass off the two legit arrests he had made in the bar to Tavarez.

“As a detective, you still have a number to reach while you are in the narcotics division,” he said.

NYPD officials did not respond to a request for comment.

Anderson worked in the Queens and Brooklyn South narcotics squads and was called to the stand at Arbeeny’s bench trial to show the illegal conduct wasn’t limited to a single squad.

“Did you observe with some frequency this … practice which is taking someone who was seemingly not guilty of a crime and laying the drugs on them?” Justice Gustin Reichbach asked Anderson.