From left, Laura Bush, George W. Bush, first lady Michelle Obama and President Obama attend an interfaith memorial service in Dallas for five officers killed in an ambush last week. (Mandel Ngan/AFP/Getty Images)

A chastened and humbled President Obama on Tuesday used a memorial service here for five slain police officers to call on Americans to overcome their racial divisions and mutual suspicion after years of relentless gun violence.

Obama’s impassioned appeal — one he has repeated often throughout his presidency — was made more powerful by confessions of his own doubt about whether he and the country are up to the task.

“I am not naive. I have spoken at too many memorials during the course of this presidency,” Obama said in one of the most reflective and personal speeches of his time in office. “I have seen how inadequate my own words have been.”

The president came to Dallas to mourn and pay tribute to the five police officers, who were killed last week while protecting marchers protesting the deaths of black men at the hands of police in Louisiana and Minnesota.

His challenge, in the midst of a bitter and polarized presidential election season, was to press Americans to be more empathetic and focus on their shared values. The task was made all the more difficult by the graphic videos of police shootings that have ricocheted across social media over the past week, spawning competing narratives about racial discrimination, inequities in the criminal justice system and the dangers of policing.

“Can we find the character, as Americans, to open our hearts to each other? Can we see in each other a common humanity and a shared dignity, and recognize how our different experiences have shaped us?” Obama asked. “I don’t know. I confess that sometimes I, too, experience doubt.”

Aboard Air Force One en route to Texas, Obama called family members of the two men killed by police in Louisiana and Minnesota to offer his and the first lady’s condolences.

In Dallas, the president praised police officers for doing difficult and dangerous work, even as he called attention to broader problems with policing practices across the nation. He consoled the mourners, even as he challenged Americans to be more open with each other, to shout less and listen more.

“If we’re honest, perhaps we’ve heard prejudice in our own heads and felt it in our own hearts. We know that,” Obama said. He acknowledged that even as Americans try to rise above bigotry and discrimination, “none of us is entirely innocent. No institution is entirely immune, and that includes our police departments,” he said. “We know this.”

Former president George W. Bush, who lives in Dallas, also addressed the mourners and sought to project a common purpose beyond politics. “Too often we judge other groups by their worst examples, while judging ourselves by our best intentions,” Bush said, in remarks that Obama would echo.

Obama’s speech was memorable for its raw quality and the president’s unmistakable frustration. The president was returning to a theme — the need to overcome rancorous partisanship and racial divisions — that has dominated his career on the national stage.

One year ago, Obama stood before an arena full of mourners in Charleston, S.C., who had gathered to remember nine black parishioners killed by a white gunman during a Bible study. In Charleston, Obama gave a soaring, spiritual and optimistic address. The country, he said, had responded to the brutal killings with a “big-hearted generosity . . . a thoughtful introspection and self-examination that we so rarely see in public life.”

He cast the killings at Emanuel AME Church as a divinely inspired turning point. In the days after the slayings, South Carolina lawmakers had voted overwhelmingly to remove the Confederate battle flag from the state capitol dome. Obama called on Americans to build on that spirit by tackling the country’s biggest and most in­trac­table problems: guns, racial discrimination, poverty.

In Dallas, he once again described a tragedy as a call to action, but this time he was more blunt than soaring. His optimism was tempered by a stream of violence in the intervening year. Since he spoke in Charleston, there have been more mass shootings: in Roseburg, Ore.; San Bernardino, Calif.; Orlando; and now Dallas. Much to his frustration, the president’s efforts to advance gun-control legislation have gone nowhere, and a bipartisan push for criminal justice reform has stalled. Racial tensions seem to have grown worse amid the recent run of police shootings and the divisive cacophony of a bitter election season.

Obama called on police and their supporters not to ignore the complaints of protesters who point to racial disparities in searches, arrests, deadly shootings and sentences as proof of police bias.

“To have your experience denied like that, dismissed by those in authority, dismissed perhaps even by your white friends . . . it hurts,” Obama said. “Surely we can see that, all of us.”

He called on protesters and civil rights activists to empathize with the plight of police officers, who are often assigned to patrol dangerous and forgotten neighborhoods without sufficient resources.

“We flood communities with so many guns that it is easier for a teenager to buy a Glock than get his hands on a computer or even a book,” Obama said. “We tell them to keep those neighborhoods in check at all costs and do so without causing any political blowback or inconvenience. . . . These things we know to be true.”

If Americans cannot speak “honestly and openly,” Obama warned, the problems will fester, and “we will never break this dangerous cycle.”

Last week, after the police shootings, protests and the Dallas ambush, Obama rejected the notion that the country was overly polarized. “As tough, as hard, as depressing as the loss of life was this week, we’ve got a foundation to build on,” he said Friday in Poland, where he was attending a NATO summit.

His remarks in Dallas focused on those glimmers of hope, optimism and unity, even as he acknowledged the country’s frustrations and the sense that divisions are getting worse.

“It’s hard not to think sometimes that the center won’t hold and that things might get worse,” Obama said. “I understand how Americans are feeling. . . . we must reject such despair.”

He praised the police officers in Dallas for sacrificing their safety to protect protesters who were marching against police misconduct, and he lauded the city’s police department for pushing through reforms after previous police shootings in places such as Ferguson, Mo.

“The Dallas Police Department has been doing it the right way,” he said.

The question for Obama is whether the country, consumed by an especially venomous election campaign to choose his successor, is still open to his message of hope.

“In the end, it’s not about finding policies that work,” he said in Dallas. “It’s about forging consensus and fighting cynicism and finding the will to make change.”

Eilperin reported from Washington.