The Philadelphia police union’s love for the city’s top prosecutor can be fleeting.

The Fraternal Order of Police enthusiastically supported Lynne Abraham — until it felt she took too long to decide whether to charge officers in shootings. That’s when the FOP endorsed her 2005 primary challenger Seth Williams. He held its favor until, as district attorney, he didn’t charge former Eagles star LeSean McCoy in a 2016 bar brawl with off-duty cops. The FOP put up a “Help Wanted” billboard along I-95 seeking a new DA.

This year, as District Attorney Larry Krasner battles longtime prosecutor Carlos Vega in the Democratic primary, the FOP has once again hoisted billboards and flooded mailboxes and airwaves in a bid to oust the incumbent. It’s helping fund a political action committee formed by retired cops that is the top spender in the race. It’s blaming Krasner for the soaring violence in the city — despite the fact that Philadelphia’s crime surge is in line with national trends. It’s even mobilizing Republicans to change their voter registration to Democratic so they can back Vega in the May 18 primary.

And in a new twist, the FOP is parking a Mister Softee Ice Cream truck outside Krasner’s office every week to cast him as “soft on crime.”

While the union’s bare-knuckle campaigning is familiar, it’s taken on a new intensity against a progressive, reform-minded prosecutor who made a career out of suing police and is running for reelection by promising to hold them accountable. Police leaders, rank-and-file cops, and political observers say that while the relationship between Philadelphia police and prosecutors has often been acrimonious, it hasn’t been this bad in decades.

Less than a week before the primary, the race between Krasner and Vega is as much a showdown between Krasner and the police.

“Our officers have given us carte blanche to spend whatever we need to spend to be able to remove this cancer from the District Attorney’s Office,” FOP president John McNesby said.

“I could care less about Larry Krasner,” McNesby added. “I’m not out here to hurt the guy. But I’m not gonna sit there and let our officers be treated the way they are.”

» READ MORE: Philly DA Larry Krasner has a race on his hands against Carlos Vega: ‘It’s closer than Larry wants’

Amid rising national crime rates during a pandemic that upended the fabric of American society, the union, which represents 14,000 current and retired officers, says Krasner is uniquely responsible for Philadelphia’s skyrocketing gun violence. It says weak prosecution of gun offenses — resulting in plea bargains and tossed cases — has emboldened shooters and threatened public safety.

Police were on pace to make 3,000 arrests this year for carrying a gun illegally, a record, but the people charged are less likely to be convicted, an Inquirer investigation found in March. Krasner, who spent three decades as a civil rights and defense lawyer, says cops are handing him weak cases.

“If we’re all going to focus on the questionable notion that everybody who possesses a gun is spending their time looking at data on what conviction rates are, then we’re going to miss any solution that’s actually going to be real and effective,” he said earlier this year.

Krasner has made his campaign about the FOP as much as about Vega, who received $25,200 from the union — the maximum allowed contribution. He notes in campaign literature that McNesby called Black Lives Matter protesters “a pack of rabid animals” and that FOP members last year drank beers with the Proud Boys, an alt-right hate group, at the union’s headquarters. Krasner has been endorsed by the the Guardian Civic League, which represents more than 2,000 active and retired Philadelphia officers.

» READ MORE: Philly gun arrests are on a record pace, but convictions drop under DA Krasner

To make its case, the FOP has poured cash into political action committees and Vega’s campaign. It donated $113,000 to Protect Our Police PAC, which is airing the only TV ads in the race. And more money is coming, McNesby said.

“We’re looking at pushing full force,” he said of the race’s final days. “We’re looking at putting the army out there and spending whatever else needs to be spent to be able to get the job done.”

Former Deputy Police Commissioner Joseph Sullivan said the union speaks for many rank-and-file officers, though many also support some police reforms.

“The cops that I talked to all understand that we’re never going back to a system of mass arrests and mass incarceration, and the majority of them agree with it,” he said. “But what they see are really dangerous people that are harming people in their own communities at will and carrying guns and returning to the streets, and they’re miffed by it.”

Abraham, a vocal Krasner critic who served as district attorney from 1991 to 2010, had support from the FOP until 2005.

“They turn on you,” she said. “You know why? If you’re doing the right thing, you’re not going to have friends and people who love you all the time because you have to make hard decisions.”

Abraham was known during her time in office as “America’s Deadliest DA” for how often she sought the death penalty, and Krasner has spent his first term exonerating people wrongfully imprisoned during her tenure. He’s made that work a cornerstone of his reelection campaign.

» READ MORE: Philly’s overturned murder cases call decades of homicide investigations into question

Williams, who was elected district attorney in 2009, said the difference between police solving a case and prosecutors proving it in court can “create a tension” between cops and the DA.

“The DA’s Office was not created to be a rubber stamp for whatever the police say or do,” Williams said. “The DA has sole discretion as to which cases should be prosecuted, who should be charged and with what crimes.”

The relationship between Krasner and the FOP was bitter from the start. In 2017, McNesby called Krasner supporters “parasites of the city” after some chanted “no good cop in a racist system” at Krasner’s election victory party.

They clashed over Krasner declining to seek the death penalty in any case, including the murder of Philadelphia Police Sgt. Robert Wilson III, and Krasner’s 2018 release of a list of “tainted cops” that the DA’s Office doesn’t call as witnesses in court.

Asked at a televised debate last week how he could improve his relationship with police, Krasner made a passing mention to “a lot of good cops out there” in the middle of what’s become a signature salvo against McNesby.

“Let’s talk about the elephant in the room, the elephant in the room is that the FOP has spent $120,000 on my opponent’s campaign ... and they’ve done it for a reason, which is that the leadership of the FOP — not a lot of [the] good cops out there — but the leadership of the FOP does not want accountability.”