Americans, he said, “can turn on the TV or surf the internet, and we can watch positions harden and lines drawn, and people retreat to their respective corners, and politicians calculate how to grab attention or avoid the fallout. We see all this, and it’s hard not to think sometimes that the center won’t hold and that things might get worse.”

But Mr. Obama insisted on holding out hope.

“Dallas, I’m here to say we must reject such despair,” Mr. Obama said, adding that he knew that because of “what I’ve experienced in my own life, what I’ve seen of this country and its people — their goodness and decency — as president of the United States.”

He cited both the Dallas police and protesters as part of that decency. “When the bullets started flying, the men and women of the Dallas police, they did not flinch and they did not react recklessly,” Mr. Obama said. “They showed incredible restraint. Helped in some cases by protesters, they evacuated the injured, isolated the shooter and saved more lives than we will ever know. We mourn fewer people today because of your brave actions. ‘Everyone was helping each other,’ one witness said. ‘It wasn’t about black or white. Everyone was picking each other up and moving them away.’”

Mr. Obama concluded: “See, that’s the America I know.”

A row of police officers behind Mr. Obama in the concert hall did not clap when Mr. Obama spoke of racial bias in the criminal justice system, saying that “when all this takes place more than 50 years after the passage of the Civil Rights Act, we cannot simply turn away and dismiss those in peaceful protest as troublemakers or paranoid.”

But when Mr. Obama added, “We ask the police to do too much, and we ask too little of ourselves,” the officers behind him applauded.