WASHINGTON — President Barack Obama said Sunday the attacks on public servants and the rule of law “have to stop,” after a second shooting spree targeting police officers in less than two weeks killed three officers in Baton Rouge and wounded three others.

Obama said the motive for Sunday’s attack was unknown, but there is no justification for violence against law enforcement.

“These attacks are the work of cowards who speak for no one,” Obama said in a statement released by the White House. “They right no wrongs. They advance no causes.”

Obama also called Louisiana Governor John Bel Edwards and Baton Rouge Mayor Kip Holden to hear the latest on the investigation into the shootings and pledge federal support.

Obama has spent most of the last week focused on defusing tensions and rebuilding trust between police departments and the communities they serve.

On July 7, an Army veteran opened fire on law enforcement in Dallas, killing five and wounding seven other officers. The shooter said he wanted to kill white people, “especially white officers.” Obama spoke at the memorial service for the five officers killed and told Americans not to despair, that the nation is not as divided as it might seem.

The next day, he held an extraordinary four-hour meeting at the White House’s executive offices with police officers, community activists and elected leaders, emerging from the session saying “we’re not even close” to the point where minority communities could feel confident that police departments were serving them with respect and equality or where police departments could feel adequately supported at all levels.

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, which sparked protests around the country. Dallas police were defending protesters in that city when the black gunman opened fire on them.