Mr. de Blasio said Mr. O’Neill was leaving to take a job in the private sector.

“It’s something I couldn’t pass up,” the commissioner said, without elaborating.

Mr. O’Neill said his decision to leave had nothing to do with his firing of Officer Pantaleo, a call he said he agonized over but defended as “the right thing.”

The dismissal of Officer Pantaleo in August drew praise from Mr. Garner’s family members and their supporters, but it angered police union officials, who said Commissioner O’Neill had lost the confidence of officers. Arrest rates briefly dropped in the weeks that followed.

Chuck Wexler , the executive director of the Police Executive Research Forum, said Mr. O’Neill had success in navigating the difficult political terrain facing all police leaders in recent years, as the Black Lives Matter movement has generated outrage over deaths of people in police custody.

“Policing the largest city in the country, he has had to face that issue, balancing community trust with motivating his own personnel,” Mr. Wexler said. “Sometimes those things are in conflict.”

Chief Shea, who will take over on Dec. 1, will step into his role at a critical moment for the Police Department, which on Jan. 1 will be forced to comply with the most significant criminal justice reforms on bail and trial discovery that the city has seen in decades.

His tenure also begins as the department wrestles with its own internal crisis — 11 current or former New York police officers have committed suicide in the last 10 months.