New York City Mayor Bill de Blasio asked congregants in a Staten Island church on Sunday not to despair in these “horrible times” as the community marked the second anniversary of Eric Garner’s death from an apparent police chokehold.

Several hundred parishioners gathered at the First Central Baptist Church — about a mile from where Garner, 43, died — to hear de Blasio say the police department has been trying to improve relations with minority communities since Garner’s death.

“The NYPD is doing an exemplary job,” said the mayor, adding that the city’s 36,000 uniformed police officers this year will be trained in “de-escalation” tactics. The mayor offered anecdotal stories of police giving their cellphone numbers to residents who live and work on their beats.

“Crime is going down and systematically we are retraining our police force,” said de Blasio, who asked church leaders to “bring in the police into the church and help them see the fullness of the community.”

But as the mayor touted the NYPD’s progress, he also informed the congregation of a shootout in Baton Rouge that killed three police officers and wounded three. There were gasps in the audience.

“This is unacceptable. These attacks on our police are attacks on all of us. It’s an attack on our democracy,” said the mayor, who spoke from a church podium. “This is an action of a few,” said the mayor, whose remarks led several congregants to reply in a unified “Yes, yes.”

In a 30-minute speech, the mayor tried to persuade parishioners to alter their perceptions about police and community relations. He said that the NYPD, which protects 8 1⁄2 million people in the largest city in the nation, has “come a long way in improving” its relations with the black community and other minorities.

The mayor talked about the 1980s and 1990s, when racial relations were volatile and “a breakout in violence” was a regular occurrence. “We have come a long way. We are more harmonious.” He said the city at that timehad a murder rate of about 2,000 annually. “Today we hover over 300.”

After Garner’s death, a Staten Island grand jury failed to indict any of the officers seen in an amateur video who were holding Garner as he was pinned down on a city sidewalk. Police attempted to arrest Garner, saying he was selling loose cigarettes in front of a convenience store. A federal grand jury is now investigating Garner’s death.

The mayor said he recognized the pain of families who suffer the death of a loved one at the hands of police. “The pain does not go away,” he said. “It hangs in the air. What we can do is hold those families in our hearts and embrace them and make sure another family does not feel that pain.” Immediate members of Garner’s family were not at the service.

Sunday afternoon, about 100 peaceful protesters gathered in front of the spot where Garner died.

Earlier in the day, de Blasio told 1010 WINS that the NYPD is retraining its officers to recognize their “implicit biases” and to “avoid the use of force when possible.”

“The real issue is preventing these tragedies and working to make sure they don’t happen again in the future,” Mayor Bill de Blasio told the news radio station. “NYPD is doing some of the very best work in this country in terms of retraining our officers on how to de-escalate incidents and how to avoid the use of force when possible. And to recognize all of us as humans have biases, have blind spots.”

With Rachel Uda