Police forces are suffering from diminishing ranks, slumping morale and declining public support as the nation nears the end of a long, fraught summer defined by protests against policing tactics and racial injustice.

Agency leaders and experts say the months of demonstrations have left officers strained and departments struggling to both recruit officers and keep the ones they have. The Portland Police Bureau in Oregon lost 49 officers to retirement in August, more than during all of 2019. The Atlanta Police Department, which became the focus of protests after a police shooting this summer, said about 140 officers have resigned so far this year, up from 80 during the same period last year.

“Our workforce in general is pretty emotionally and physically fatigued,” said William H. “Skip” Holbrook, the police chief in Columbia, S.C.

Weary officers were further shaken by the Sept. 12 ambush shooting of two Los Angeles County Sheriff’s deputies as they sat in a police car. One is still hospitalized while the other has been released.

After the shooting, Sheriff Alex Villanueva said that critics of police need to “stop fanning the flames of hatred.” Officials have not identified a potential suspect or motive in the attack.

There has been no spike in fatal shootings of police this year, and deaths in the line of duty have declined since the 1970s. But officials say an attack on an officer resonates everywhere, and the coronavirus pandemic has only added to the toll on police.

Combined with the surge in nationwide demonstrations and calls to defund their departments, police in the United States say they feel under siege.

“The police feel really . . . pushed into a corner,” said Chuck Wexler, executive director of Police Executive Research Forum, which works with police agencies.

“The George Floyd incident was a defining moment in the country,” he said. “But for policing, every day putting on that uniform, and having to respond to people thinking . . . ‘Are they a good cop or are they a bad cop?’ And that’s difficult to live with.”

This summer also brought a string of high-profile videos of police violence, including the footage of Floyd begging for air beneath an officer’s knee and the recording of a Kenosha, Wis., officer firing into Jacob Blake’s back. A wave of videos in between captured police using force on demonstrators both peaceful and destructive.

Public opinion on policing has shifted. In a survey this summer, the Pew Research Center found that while most Americans still believe police do an excellent or a good job protecting people from crime, the percentage of people who think they use the right amount of force, treat racial groups equally and hold officers accountable for misconduct all fell by double-digit points since 2016.

Amid the spate of viral videos of police violence, declining public faith in law enforcement could have an impact on how well officers can police communities, said Dennis Kenney, a professor at the John Jay College of Criminal Justice and a former police officer.

“The police are in a precarious position, where their ability to be effective is dependent on the willingness of the public to . . . collaborate with police,” he said. “It’s not so much that people no longer fear the police, which is what the law and order argument is. It’s that they no longer trust the police.”

Being filmed by bystanders is now the norm, some police say. Officers with the Ann Arbor Police Department in Michigan have reported that drivers pass police cars with a middle finger raised or shouting profanities, according to Lt. Mike Scherba, who leads the department’s special services section.

“It’s kind of different now,” he said. “I think people are maybe a little more brazen about doing things like that to show their displeasure with law enforcement.”

Activists and advocates for police reform say fundamental change is needed in how law enforcement operates, including calls to slash funding.

“In the Ferguson period, the talk was how do we change police,” Wexler said. “In the George Floyd period, it’s how do we do without the police.”

These issues have become a significant part of the presidential campaign, as President Trump has touted his support for police, denounced Black Lives Matter protesters as “agitators and thugs” and sought to highlight unrest in big cities. Joe Biden, the Democratic presidential nominee, has said he believes most police officers are good and called for policing overhauls, including linking federal funding to agencies’ adoption of use-of-force policies and body-worn cameras.

After the Los Angeles deputies were shot, Trump tweeted: “Animals that must be hit hard!” In a statement, Biden condemned the shooting and called violence against police “unacceptable, outrageous, and entirely counterproductive to the pursuit of greater peace and justice in America.”

Phillip Atiba Goff, co-founder and chief executive of the Center for Policing Equity, called the shooting horrifying and said “high profile ambush-style assaults on law enforcement make it harder” for discussions of reform to happen, since they can leave police feeling even more under attack.

“It heightens the foxhole mentality that many law enforcement are feeling right now,” he said.

Najee Ali, a prominent community activist in Los Angeles, said he saw the accusations on social media that rhetoric from critics of the police was to blame for the shooting.

“The only thing we’ve tried to do is hold law enforcement accountable. . . . we are not anti-law enforcement,” said Ali, adding that he brought flowers and balloons to the hospital for the injured deputies. “We support law enforcement. We are simply anti-law enforcement police abuse and police shooting of unarmed people.”

That shooting came a few months after an Air Force sergeant was charged with murder and accused of fatally shooting a federal security officer near an Oakland, Calif., courthouse. He has also been charged with killing a Santa Cruz County sheriff’s deputy. The FBI said he was a supporter of the “boogaloo” movement seeking to overthrow the government and, authorities alleged, sought to use racial-justice protests in Oakland as a cover for the attack near the courthouse.

So far this year, 37 officers in the line of duty have been fatally shot, compared to 35 at the same point last year, according to the National Law Enforcement Officers Memorial Fund, which tracks line-of-duty deaths. (In a report on the first six months of the year, the fund found that most of the fatal shootings of officers occurred while they were investigating reports of suspicious people or activities, trying to arrest someone or responding to a domestic disturbance call.)

The coronavirus pandemic has posed a far greater mortal threat to police this year, killing at least 102 officers, more than gunfire, car crashes and other causes combined, according to preliminary data from the memorial fund.

But some big cities are also facing an increase in gun violence, which police say creates its own risks. In Chicago, which has seen an increase in murders, David Brown, the police superintendent, said officers were “taking guns off the street at great risk to our personal safety.”

Brown said 65 police officers had been shot at, and 10 of them struck, so far this year. “There’s not a comparable year,” Brown said during a briefing Monday. “That’s five times any previous year that anyone can recall in this city.”

“We’re risking everything,” he said.

Public distrust of police is not new in many communities of color. About 7 in 10 officers in police departments in 2016 were White, according to Justice Department data, with smaller departments likely to have even larger shares of White officers. The percentage of Black officers, meanwhile, has remained essentially even at about 11 percent between 1997 and 2016.

Capt. Aaron McCraney of the Los Angeles Police Department, who oversees its hiring and recruiting, said he and Michel Moore, the police chief, are focused on recruiting women and African American officers. But, he said, recruiting Black officers is particularly challenging because of the public distrust.

“Anyone who gets hired on this department is going to go through me,” said McCraney, who is Black. “It’s important as an African American to be in this position and to be able to have that kind of impact. If I’m not here to do that, then who is?”

Departments are also struggling to keep officers in place as well as to recruit.

“Most places would report difficulty in hiring and retaining police officers,” said Holbrook, the chief in Columbia, the South Carolina capital. “The environment surrounding law enforcement in the last five years in particular has . . . given people pause, that [this] may not be the profession for them.”

The New York Police Department, the country’s largest local force, said that between the beginning of March and this week, more than 1,600 officers retired and more than 1,800 filed for retirement, both significantly up from the same period last year.

In Minneapolis, at least 100 officers have left the department since Floyd’s death in May, accounting for more than 10 percent of the force, according to Chief Medaria Arradondo. That number is expected to increase as the city makes its way through medical claims filed by officers who say they are suffering from post-traumatic stress disorder or other injuries resulting from the protests.

In a public meeting Tuesday with the Minneapolis City Council, Arradondo said the retirements have come amid a wave of violence since Floyd’s death. Nearly 400 people have been shot across the city and more than 50 killed so far this year — the highest numbers in five years, with most of the incidents reported in the nearly four months since Floyd’s Memorial Day death.

Several city council members questioned the police responses in Minneapolis and whether officers were deliberately not responding to incidents, citing reports from constituents who said their 911 calls often went unanswered or that officers told them they lacked resources to stop crime.

“Rank and file officers on the street are telling them that they are not enforcing crime,” said Lisa Bender, the president of the city council who represents an area of South Minneapolis, suggesting that officers were trying to make a political point.

Arradondo has denied that police are pulling back and said he would investigate the claims presented at the meeting.

Holly Bailey in Minneapolis contributed to this report.