Philadelphia’s police commissioner resigned Tuesday amid allegations that members of his department engaged in harassment and racial and gender discrimination against two women serving in the ranks.

Mayor Jim Kenney said in a news release he was disappointed to lose Commissioner Richard Ross Jr., but in light of the new allegations, he said Ross’ “resignation is in the best interest of the department.”

Kenney spokeswoman Deana Gamble said Ross offered his resignation after Kenney learned details of the allegations.

The corporal and patrol officer made the allegations against several department employees. Gamble said Ross knew about the alleged harassment and failed to respond adequately.

An amended version of the women’s federal lawsuit was filed Monday.

“The mayor wanted to figure out what occurred,” Gamble said. “After he read the complaint, the mayor decided to accept his resignation.”

Ross, who is black, joined the department in 1989 and had served as commissioner since January 2016. He did not respond to messages seeking comment.

The lawsuit alleges discrimination, a hostile work environment, retaliation and other counts.

The lawsuit, in which Ross and the city are among the defendants, was filed by a corporal and an officer, one black, the other black Hispanic.

The women’s civil lawyer, Ian Bryson, said they had not expected Ross to resign.

“If that’s what it takes to shed light on this issue, then we see it as a win for working people,” Bryson said.

The mayor said an unspecified independent entity will investigate the recent allegations and recommend how to address discrimination and harassment within the police agency.

Asked if the city has taken any personnel action related to the lawsuit and Ross’ departure, Gamble responded that an internal investigation is currently underway.

The city police have had a checkered relationship with the people they serve, and this summer about 100 people protested outside police headquarters, demanding action in response to reports some officers had made racist and violent social-media posts.

Ross said the day he took the job that it was a “challenging time for law enforcement” and acknowledged the department had “some issues.”

“We have to confront them and we have to be bold about it,” Ross said in 2016.

John McNesby, president of the police union, called Ross “a shining example that hard work and dedication can lead you to the top of your profession” and said he served with honor and respect.

Just last week, Kenney called Ross the best police commissioner in America after a gunman’s long standoff with police.

But during that standoff, hostility between residents and police was evident, as residents harassed officers trying to keep peace at the scene.

Kenney named Deputy Commissioner Christine Coulter to serve as acting commissioner during a search for Ross’ replacement.

(AP)