He’s been sued 20 times over alleged police brutality and other misconduct — and portrayed as a prime example of everything that’s wrong with the NYPD.

But following the dismissal of three cases earlier this month, ­Detective David Terrell says he’s living proof that the city’s willingness to settle bogus suits has led to “open season on police officers” in the court system.

“Someone gets arrested, and the arrest doesn’t go through — they sue the cops. And that has an ­effect on your job,” he said.

“Cops are scared to do their jobs.”

Terrell, who’s currently on modified duty over allegations unrelated to any litigation, is also fighting fire with fire.

In April, he filed a sprawling civil-rights suit against defendants including a law firm that has lodged 10 cases against him, and several journalists he says smeared him with false and defamatory reports on the unproven allegations.

Terrell’s Brooklyn federal-court filing also accuses the de Blasio administration of paying $614,500 to settle a 2013 case, in which Terrell was among 11 NYPD defendants, “without consulting him” first.

Court and city records show that four other cases against Terrell were also settled, for amounts ranging from $9,000 — which Terrell’s lawyer called “nuisance-value money” — to $66,000.

Seven suits against Terrell have been dismissed and eight are pending. Most also named other cops as co-defendants.

The dismissed suits include one in which Terrell was accused of beating a prisoner, Anthony Floyd, inside a holding cell, breaking his nose and fracturing his eye socket.

But in an Aug. 2 ruling, Manhattan federal Judge Loretta Preska said the NYPD records Floyd presented as evidence “demonstrate a complete lack of personal involvement by Detective Terrell … and instead demonstrate the involvement of a different police officer.”

“I’ve become such a target that I’m getting sued for making arrests when I wasn’t even on duty or there, period,” Terrell said.

Terrell, who has racked up more than 1,000 arrests since joining the NYPD in 2002, was sued just four times during his first decade on the job.

But he’s been slapped with 13 suits since November 2016, with all but three brought by the Manhattan law firm Nwokoro & Scola.

The firm’s flurry of litigation includes seven suits filed between April and August 2017, three of which were lodged on July 28 of that year.

Terrell blames the barrage on a “cottage industry” of anti-cop litigation fueled by an NYPD cop-turned-private investigator named Manny Gomez, whom Terrell calls “the one main person behind these lawsuits.” Gomez is among the defendants named in Terrell’s civil-rights case.

“He gathered all these guys together with this law firm and they decided to come up with these frivolous lawsuits, and they’d throw it all in the pot and the city would settle,” Terrell said.

“But they never banked on me fighting back.”

Terrell, 45, never planned on becoming a cop.

The older of two boys born to a housing cop and a nurse, his family lived in Laurelton, Queens, until his parents split when he was around 4.

His mom moved him and his brother to Bedford-Stuyvesant, where he spent his preteen years watching the crack epidemic ravage the Brooklyn neighborhood with drug-related violence.

Terrell said his family’s apartment was burglarized six times, and a kid who lived in their building was killed by stray bullets.

“It was very crime-ridden: gunshots all the time,” he recalled.

“It got to the point where they would shoot, and we’d have to go into the closet — me and my brother — and my mom would have to put a refrigerator in front of the closet door so we wouldn’t get hit.”

When he was 14, his mom remarried and the family moved to Freeport, LI.

“There was no violence,” he said. “That was the first time I was actually ever around any ethnicity outside of black; the first time I was around white or Chinese. It was a bit of culture shock.”

He graduated Baldwin HS and then attended Queensborough Community College and then Albany State University in Georgia.

For four years after that, he traveled around playing basketball for $600 a game before blowing out his achilles tendon.

He was looking for work when the Sept. 11, 2001, terror attacks changed everything.

“I spoke to my dad, and he was telling me to take the test to become a police officer,” Terrell said.

“I said, ‘I don’t want to be no pig’ … but it was so hard to find a job during 9/11, so I took the test for corrections and NYPD — and NYPD called first.”

He was assigned to Bed-Stuy’s 77th Precinct, where he took part in then-Police Commissioner Ray Kelly’s “Operation Impact” initiative, which flooded high-crime streets with 1,000 uniformed cops.

He later transferred to the 42nd Precinct in The Bronx, moved to Rockland County — and was promoted to detective in 2015.

The following year, Terrell was slapped with the first of 13 ­rapid-fire lawsuits.

Much of the litigation was filed by or on behalf of teens and young men Terrell claims in court papers are members of gangs, including the Lyman Place Crew, the Hill Top Crew and the B-Road Goons.

One suit was filed by Kenny Shenery, who was playing dice with friends outside a Bronx building on May 18, 2015, when a uniformed Terrell and his partner cuffed Shenery and tossed him in the back of a squad car for playing his car stereo too loudly.

Cellphone video shows Terrell joining the dice game, with Shenery claiming that Terrell offered to release him if Terrell lost — only to renege on the deal and lock him up for 48 hours.

Shenery, who was wanted on a bench warrant, later pleaded guilty to a noise summons, but he sued Terrell in 2017, following a TV news report that included the video of Terrell shooting dice.

Terrell said “rolling dice with some of the worst guys in the neighborhood” led him to solve a series of robberies with the help of “one of the guys in the video.”

He noted, “That is community policing.”

This month, Manhattan federal Judge Lorna Schofield tossed the case, saying Shenery’s guilty plea and warrant justified his arrest and imprisonment.

Another suit was filed by Shawn Nardoni, who was shot in the leg by an assailant on Sept. 1, 2015, then arrested when he got out of the hospital.

Nardoni, then 15, was brought to the 42nd Precinct station house, where he claims Terrell “badgered” him to give up the identity of the shooter, including a threat to kick his head through a wall.

Nardoni’s suit accused Terrell of falsely arresting him, but Manhattan federal Judge Gregory Woods dismissed the case this month, saying that while it’s “undisputed” that Terrell interviewed Nardoni, he “has developed no further facts … to suggest the detective was the driving force behind his arrest.”

Nardoni’s shooting was ultimately alleged to have been committed by Pedro Hernandez, who has two suits pending against Terrell.

Hernandez — who is identified in his suits as “P.P.H.” — became a cause célèbre for bail reform when he turned down a no-jail plea deal and spent a year on Rikers Island until a human-rights group posted $100,000 to bail him out in July 2017.

In October, Bronx District Attorney Darcel Clark dropped all charges against Hernandez, citing “inconsistent and contradictory” evidence and saying “the victim of the shooting is unable to identify who shot him.”

Clark also alluded to Hernandez’s allegations about Terrell by saying she “will not tolerate misconduct by law enforcement” and noting that her Public Integrity Bureau was “investigating allegations related to this matter.”

Hernandez is awaiting trial in a 2015 knifepoint robbery.

Two other pending suits were filed by Salim Wilson and ­Julio Velasquez, two Bronx buddies who wound up on opposite sides of a gun, with Wilson allegedly killing Velasquez in the McKinley Houses on Aug. 29, 2017.

Law enforcement sources have said the fatal dispute involved roughly $30,000 each man was advanced by the Brooklyn-based LawCash firm against potential settlement of their cases.

Terrell’s civil-rights suit names LawCash among the dozen-plus defendants, claiming that the firm is part of a conspiracy to destroy him that also involves Nwokoro & Scola; Gomez; activist and writer Shaun King; and TV reporters Sarah Wallace of NBC-4 and Jay Dow and James Ford of PIX-11.

LawCash co-founder and CEO Dennis Shields, the on-again, off-again boyfriend of reality star Bethenny Frankel, died of a suspected prescription-drug overdose in his Trump Tower apartment on Aug. 10.

Terrell has been stripped of his badge and gun since July 2006, when he allegedly failed to notify brass about an order of protection filed against him by his now ex-wife.

Other disciplinary charges were added over a dispute with an NYPD highway cop and Terrell’s challenge to fight the cop at an unofficial police boxing match called a “smoker” — and an inspection that found Terrell’s handgun a bullet short of loaded.

“It was one bad month I had,” Terrell admitted.

He now works security at Manhattan Criminal Court while awaiting a verdict in his NYPD trial.

Terrell’s lawyer, ex-NYPD cop Eric Sanders, is highly critical of Police Commissioner James O’Neill’s response to the lawsuits.

“O’Neill did not support him. He didn’t do the right thing for his employee. It’s disgraceful,” Sanders said.

“[Terrell] did the job, he exceeded at it and took all these dangerous gang members off the street, and this is the thanks he gets? They left him out to dry.”

Gomez denied any wrongdoing, saying, “My work speaks for itself … There is nothing shady. I have relationships with all attorneys.”

City Hall spokeswoman Olivia Lapeyrolerie said: “This administration has improved the city’s fact-finding process, filed more motions to dismiss cases, and added resources and personnel to reduce settlements and challenge more frivolous allegations.”

PIX owner Tribune Media said Terrell’s allegations “have no merit and we will vigorously defend the suit,” and court papers say LawCash’s parent “intends to move to dismiss the claims.”

The NYPD declined to comment and Nwokoro & Scola, King and NBC-4 didn’t return inquiries.