Police Commissioner James O’Neill announced his resignation Monday amid record-low New York City crime rates — while privately warning that extreme criminal-justice reform could unravel the hard-won gains.

“It’s only gonna get worse,” O’Neill repeatedly said in the weeks before his resignation, referring to the Big Apple’s climate under criminal-friendly initiatives out of City Hall and Albany like Raise the Age and bail reform, according to police sources.

O’Neill, 62, will finish out the month as top cop before turning over the keys to the NYPD to current Chief of Detectives Dermot Shea, 50, and decamping for a private-sector gig in California.

“I came into this job with one mission, and that was to fight crime and keep everybody safe,” said O’Neill, whose last day will be Dec. 1, during a City Hall press briefing. “And we did it, and we continue to do it.”

But while O’Neill publicly wore a smile and maintained that he was moving on only because he received a private-sector offer he “couldn’t pass up,” he fumed behind closed doors that soft-on-crime measures at the city and state levels threaten to undo the best efforts of the Finest, sources said.

He specifically referenced the Raise the Age initiative — which lets many 16- and 17-year-old suspects avoid being charged as adults — and bail reforms taking effect next year that will see more suspects released pending trial for crimes including non-violent felonies, sources said.

The responsibility for guiding the NYPD through waters increasingly hostile to law-enforcement will now fall to Shea — a 28-year department veteran widely known as an ardent devotee of CompStat and analytics-driven policing — who becomes Mayor de Blasio’s third top cop after O’Neill and Bill Bratton.

“We’ve redefined in the last six years how we police this great city,” said Shea, touting NYPD efforts to drive down crime as well as arrests. “We’ve done what many said was impossible. [But] we cannot and will not rest until all New Yorkers feel safe.”

De Blasio expressed total confidence in Shea’s ability to guide an NYPD that has been beset in recent months by anti-police vitriol in the streets, reports of flagging morale and an epidemic of cop suicides.

“Dermot brings a wealth of leadership experience, and he knows what policing needs to be in the 21st century,” said Hizzoner. “He definitely has big shoes to fill, but Dermot Shea is ready.”

O’Neill agreed.

“I know Dermot is the right person, and it’s the right time,” he said. “New York is in great hands.”

Shea’s successor was not immediately named.

O’Neill spoke frankly about the stresses of leading the nation’s largest police force under de Blasio since September 2016 — advising Shea, “this is a job that consumes you” — but admitted that he does not leave easily.

“I’m gonna miss it,” said O’Neill, who took a moment during his remarks to name each of the Finest who died in the line of duty on his watch — as well as a handful from years prior.

“I love being a cop,” he said.

Flatbush-reared O’Neill’s storied law-enforcement career began in 1983, when he joined the Transit Police — then a distinct entity from the NYPD.

By the time the Transit Police and Housing Police were absorbed by the NYPD in 1995, O’Neill had attained the rank of lieutenant — but his rise through the ranks had only begun.

He was eventually named the executive officer of the 52nd Precinct in the northern Bronx, and went on to lead three other commands — Central Park, East Harlem’s 25th Precinct and the Bronx’s 44th Precinct — as well as citywide units, including vice and narcotics.

Following stints as Chief of Patrol and Chief of Department under Bratton, O’Neill was tapped by de Blasio as the NYPD’s 43rd commissioner.

The O’Neill era was marked by a record-low crime rate, including murders, as well as a deeper commitment by the NYPD to using analytics and neighborhood policing — a push credited with driving down crime while strengthening relationships between cops and those they protect.

O’Neill, however, often found himself caught on the tightrope that was striving to simultaneously please City Hall and rank-and-file cops — a balancing act exemplified by the handling of Officer Daniel Pantaleo’s fate.

The Staten Island cop — charged departmentally in Eric Garner’s 2014 death — was ultimately fired by O’Neill in August, leaving many within the department feeling betrayed.

That sentiment earned O’Neill a scathing send-off from Sergeants Benevolent Association President Ed Mullins.

“Like any coward, Commissioner O’Neill chose to run off before the entire empire falls,” said Mullins in a statement. “I believe he will go down as the worst Police Commissioner in NYPD history.”

But O’Neill said Monday that how he’s remembered is of little interest to him.

“I’m not particularly concerned about my legacy,” he said. “I think that all the work that we all do together, the executive staff and 54,000 members of the New York City Police Department, I think that speaks for itself.”

Additional reporting by Craig McCarthy and Lia Eustachewich