A former NYPD narcotics detective snared in a corruption scandal testified it was common practice to fabricate drug charges against innocent people to meet arrest quotas.

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.