President Obama gave remarks on the Dallas shooting that has left at least five police officers dead, while at a summit in Warsaw, Poland, on July 8. (Reuters)

President Obama gave remarks on the Dallas shooting that has left at least five police officers dead, while at a summit in Warsaw, Poland, on July 8. (Reuters)

For nearly two years since the eruption of racial unrest in Ferguson, Mo., President Obama has tried to strike a careful balance between support for police officers and greater scrutiny of the policing tactics used against members of minority groups.

But with angry protests spreading across the country over viral videos of police shootings of black men in Louisiana and Minnesota, Obama chose this week to make a forceful statement about the “serious problem” of racial bias among law enforcement.

“All Americans should be troubled by these shootings,” Obama declared late Thursday, “because they are not isolated incidents.” He praised officers for their service, but he also cited statistics showing that blacks and Hispanics are arrested and incarcerated at higher rates than whites. This, Obama said, is “why emotions are so raw.”

Then, within hours, an African American former soldier fired on officers in Dallas during what began as a peaceful protest march over police brutality, killing five officers and injuring seven others.

It was the single deadliest day for law enforcement in the United States since the terrorist attacks of Sept. 11, 2001.

At least five Dallas police officers were killed and seven wounded July 7, after a peaceful protest over recent police shootings. Here's what we know so far. (Deirdra O'Regan/The Washington Post)

The horrific episode prompted Obama, attending a NATO summit here, to condemn the “vicious, calculated, despicable” act in Dallas and reiterate that police have “an extraordinarily difficult job.”

“Today is a wrenching reminder of the sacrifices they make for us,” he said.

It was also a reminder of the tenuous path the first black U.S. president has pursued as he seeks to calm racial tensions and mend relations between police and the communities they serve.

His approach has been criticized on both sides. Some civil rights advocates have complained that the president waited too long at times to weigh in on disputed police shootings and to give voice to the long-standing pain and mistrust of police in many black communities.

Meanwhile, some law enforcement officials have accused Obama of unfairly blaming the police and making their dangerous jobs even riskier. Last year, the administration banned the federal transfers of certain types of military-style assault gear to local police departments in the wake of the protests in Ferguson, where an unarmed black teenager was fatally shot by a white officer in 2014.

“From our view, what’s going on today, this summer, all this year — it really is a war on cops,” said William Johnson, executive director of the National Association of Police Organizations, which represents 241,000 officers. “Mr. Obama is proving, and his administration is proving, to be the Neville Chamberlain of this war. They are appeasing those who hate the police and those who threaten violence.”

White House aides rebutted such criticism, emphasizing the praise Obama has lavished on the vast majority of officers who “put their lives on the line to protect us” and pointing out his acknowledgment of the counsel he has sought from police. Obama established a federal task force in December 2014 to recommend policy options on “21st century policing.” The panel was led by Charles H. Ramsey, a former police chief in Philadelphia and Washington.

Patrick Zamarripa, Lorne Ahrens, Michael Smith and Michael Krol of the Dallas Police Department and Brent Thompson of Dallas Area Rapid Transit are the five victims who were killed in Thursday's shooting in Dallas. Seven others were wounded. (Erin Patrick O'Connor/The Washington Post)

But Obama acknowledged the backlash during his remarks Thursday in Warsaw after Alton Sterling in Baton Rouge and Philando Castile in Falcon Heights, Minn., both of whom were black, were killed this week by white officers.

“I get letters — well-meaning letters sometimes — from law enforcement saying, ‘How come we’re under attack? How come not as much emphasis is made when police officers are shot?’ ” the president said.

Referring to the Black Lives Matter movement, which was founded in the aftermath of the Ferguson shooting, he added that supporting that effort “doesn’t mean blue lives don’t matter; all lives matter. But right now, the big concern is the fact that the data shows black folks are more vulnerable to these kinds of incidents. . . . And we should care about that. We can’t dismiss it.”

Obama’s response was an attempt to contain and channel the national outrage over the deaths of Sterling and Castile. As cable news channels carried blanket coverage Thursday of the Baton Rouge and Minnesota shootings, the president did not wait for Air Force One to land in Warsaw to post an initial response on his official Facebook page. Less than an hour after landing, he spoke on camera to reporters.

In the past, Obama has frustrated civil rights leaders by taking longer to react, cautioning that he must wait until local and federal investigations have been completed.

Some of the president’s allies attribute his reticence to an incident just months into his first term, when he criticized the Cambridge, Mass., police department for a white officer’s alleged mistreatment of Harvard University professor Henry Louis Gates Jr. Amid fierce criticism from Republicans and law enforcement leaders, Obama later said he regretted his words and invited Gates and the officer to the White House to mend the hard feelings over beers.

In the aftermath of the Ferguson shooting in August 2014, skirmishes erupted between local residents and police while Obama was vacationing on Martha’s Vineyard. He resisted calls to visit the city, dispatching instead then-Attorney General Eric H. Holder Jr.

Since then, Obama has tried to balance his critique of the police by tempering expectations of black activists. During remarks at Howard University’s commencement in May, Obama alluded to the Black Lives Matter movement and cautioned that “you have to go through life with more than just passion for change; you need a strategy. . . . Change requires more than righteous anger.”

On Friday, Obama spoke by phone with Dallas Mayor Mike Rawlings and offered full federal assistance to the investigation into the attack on officers. He added that the FBI has been in touch with local officials. But that was not enough for some critics. The Fraternal Order of Police called on the Justice Department to open a federal investigation into the Dallas shootings as a hate crime.

The department “is always quick to insert itself into local investigations, sometimes before the preliminary reports are in,” Chuck Canterbury, the organization’s president, said in a statement. “Today we expect action just as swift.”

In Poland, making his first remarks on the shootings in Louisiana and Minnesota, Obama had called for a different kind of response to the tragedies.

“I hope we don’t fall into the typical patterns that occur after these kinds of incidents occur, where right away there’s a lot of political rhetoric and it starts dividing people instead of bringing folks together,” he said.

By Friday evening, White House officials, amid all of the discordant voices, pointed to some positive signs, praising Republican House Speaker Paul D. Ryan (Wis.) for his measured response and focus on the values that unite Americans.

The challenge for Obama will be nurturing and sustaining that spirit in an already venomous election season.

Nakamura reported from Washington.