President Barack Obama denounced the police killings in Baton Rouge during a news conference Sunday afternoon, calling on the country to unite against violence.

"Regardless of motive, the death of these three brave officers underscores the danger that police across the country confront every single day," Obama said during a White House news conference. "We as a nation have to be loud and clear that nothing justified violence against law enforcement. Attacks on police are an attack on all of us and the rule of law that makes society possible."

Obama, who noted he was just in Dallas days ago for memorials for slain officers there, offered his condolences to the families of the three Baton Rouge victims and prayers to one of the three other injured officers who is in critical condition.

The President said he spoke earlier in the day with Louisiana Gov. John Bel Edwards and Baton Rouge Mayor Kip Holden to hear the latest on the investigation into the shootings and pledge federal support. He said the FBI is investigating the incident.

"Through the work of all levels of government justice will be done," Obama said.

The President spoke on the eve of the Republican Party's national convention, where Donald Trump will officially accept the GOP nomination. Trump, using heated rhetoric, has called for new leadership in the country in the wake of the Dallas police ambush and recent killings carried out by police. Next week the Democratic Party will hold its convention.

Obama called for the country to put politics aside and unite against violence.

"We have our divisions and they are not new. Around-the-clock news cycles and social media sometimes amplify these divisions and I know we're about to enter a couple weeks of conventions where our political rhetoric teds to be more over-heated than usual," he said. "That's why it is so important that everyone regardless of race or political party or profession, regardless of what organizations you are a part of — everyone right now focus on words and actions that can unite this country rather than divide it further."

While Obama didn't mention Trump, he said, "We don't need inflammatory rhetoric we don't need careless accusations thrown around to score political points or to advance an agenda."

He called on Americans to "temper our words and open our hearts."

Obama has spent most of the last week focused on alleviating tensions and building trust between police and communities following the July 7 shooting of law enforcement officers in Dallas.

An Army veteran opened fire on police, killing five and wounding seven. The shooter, who was black, said he wanted to kill white people, particularly white police officers.

Dallas police were defending protesters when the gunman opened fire on them.

The shooting of the police officers in Dallas and Baton Rouge were preceded by police shootings of two black men, Alton Sterling in Baton Rouge and Philando Castile in suburban St. Paul, Minnesota. Their deaths sparked protests across the country, including Black Lives Matter demonstrations in Newark and Morristown.

Speaking at a Dallas memorial service this week, the president said the country is not as divided as it may seem.

On Sunday he called on the country to come together again as it did after the Dallas shooting.

"We need what we saw in Dallas this week as a community came together to restore order and deepen unity and understanding," he said. "We need the kind of efforts we saw this week in meetings between community leaders and police — some of which I participated in — where I saw people of good will pledge to work together to reduce violence throughout all of our communities."

He said it's up to everyone to make sure they are part of the solution, rather than part of the problem.

"Only we can prove that  we have the grace and the character and the common humanity to end this kind of senseless violence, to reduce fear and mistrust within the American family, to set an example for our children," he said. "That's who we are and that's who we always have the capacity to be. And that's the best way for us to honor the sacrifice of the brave police officers who were taken from us this morning."

As he said following the Dallas shooting, Obama reiterated that this would not be the last example of a person that tries to make the country turn against each other. But he said Americans must work to continually fight this type of violence.

"Someone once wrote a bullet need happen only once, but for peace to work we need to be reminded of its existence again and again and again," Obama said. "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."

The Associated Press contributed to this report.

Sign up for the Newsletter

Get the best of delivered to your inbox every day.