President Obama condemned the attack on Baton Rouge police officers that resulted in the death of three officers and the wounding of three others, calling on the American people to "temper our words and open our hearts."

"Regardless of motive the death of these three brave officers underscores the danger that police across the country confront every single day," he said at the White House Sunday afternoon. "And we as a nation have to be loud and clear that nothing justifies violence against law enforcement. Attacks on police are an attack on all of us and the rule of law that makes society possible."

Mr. Obama said tragedies like Baton Rouge have "happened far too often," referring also to the recent shooting of Dallas police officers earlier this month.

Get Breaking News Delivered to Your Inbox

"I've spent a lot of time with law enforcement this last week. I'm surrounded by the best of the best every single day and I know whenever this happens, wherever it happens, you feel it," he said. "What I want you to know today is the respect and gratitude of the American people for everything you do for us."

He especially urged caution over "inflammatory" words as the Republican and Democratic conventions are about to begin, noting that convention season is a time when "our rhetoric tends to be more overheated than usual."

"My fellow Americans, only we can prove through words and through deeds that we will not be divided and we're going to have to keep on doing it again and again and again," he said.

He offered the full support of the federal government to the Baton Rouge police department and mayor and to Louisiana Gov. John Bel Edwards.

"[M]ake no mistake," he promised, "justice will be done."

Mr. Obama noted that he called Bel Edwards and Baton Rouge Mayor Kip Holden to get an update on the investigation into the shooting, and he offered his condolences to the families of the slain officers.

Presumptive Democratic nominee Hillary Clinton also condemned the attack Sunday, saying in a statement that there is "no justification for violence."

Today's devastating assault on police officers in Baton Rouge is an assault on all of us. There is no justification for violence, for hate, for attacks on men and women who put their lives on the line every day in service of our families and communities.