Gregory Korte

USA TODAY

WARSAW — President Obama will cut short his four-day trip to Europe and instead return to Washington following the shooting deaths of five police officers in Dallas on Thursday, the White House said.

Instead, Obama will travel to Dallas early next week at the invitation of Mayor Mike Rawlings, and devote most of his week to addressing the racial and policing issues raised by the events of the past few days, said White House Press Secretary Josh Earnest.

That announcement capped a long 24 hours in Warsaw, where Obama was meeting with NATO allies. He condemned the videotaped police shootings of two black men in Louisiana and Minnesota shortly after touching down in Warsaw, and then awoke to the news of five Dallas police officers being killed by a sniper.

In between meetings with European leaders, he called the assault a "vicious, calculated and despicable attack on law enforcement."

"I believe I speak for every single American when I say we are horrified over these events, and we stand united with the people and the police department in Dallas," he said.

Obama will skip his day of sightseeing and troop visits in southern Spain and instead meet with Spanish officials in Madrid on Sunday. He'll then return to Washington Sunday night, a day ahead of schedule.

Obama had been scheduled to visit Seville, where he would have toured the cathedral and royal palace with Spanish King Filipe VI. Obama will continue his plans to stop in Rota, the southern Spanish port city where four U.S. destroyers are based, to tour a destroyer and talk to troops.

The decision to cut short a foreign trip is not one that the White House takes lightly. Obama went ahead with plans to attend a baseball game in Havana with Cuban President Raul Castro after a terrorist attack in Brussels in March — famously doing "The Wave" with Castro — and then flew on to Argentina. But last year, he canceled a sightseeing trip to the Taj Mahal to instead pay his respects to the new king of Saudi Arabia, Salman, after the death of his half brother, King Abdullah bin Abdulaziz.

White House officials were clearly agonizing over the decision Friday, with Earnest telling reporters it was something they were "following closely."

"One of the challenges of the presidency is the person who is entrusted with the responsibility of leading the country has to be able to focus on and devote significant attention to more than one priority at a time," he said.

In a statement later, Earnest said Obama use the week to "continue the work to bring people together to support our police officers and communities, and find common ground by discussing policy ideas for addressing the persistent racial disparities in our criminal justice system."

Those seemingly irreconcilable goals came into sharp focus overnight Thursday and into Friday, as Dallas police said at least five officers were killed and seven more injured by gunfire in downtown Dallas during what had been a peaceful protest over police-involved shootings. After almost an hour of negotiations, the heavily armed gunman — who was holed up in a building that overlooked the protest route — was killed by police using a robot-controlled explosive device. Three other people have been arrested.

"We will learn more, undoubtedly, about their twisted motivations, but let’s be clear: There is no possible justification for these types of attacks," Obama said. "Anyone involved in the senseless murders will be held fully accountable. Justice will be done."

As he did earlier Friday, Obama called on Americans to bridge the divide in police-community relations, supporting officers and their families while addressing racial disparities in police-involved shootings and the criminal justice system at large. And renewed his call for action on gun control: "We also know that when people are armed with powerful weapons, it makes shootings like this more deadly and more tragic," he said.

But he said his immediate concern was for the officers and their families. "Today is a wrenching reminder of the sacrifices they make for us," he said. "They are heartbroken. The entire city of Dallas is grieving. Police across America, which is a tight-knit family, feels this loss to their core. And we're grieving with them."

Chief: Suspect in Dallas police slayings 'wanted to kill white people'

It was the second time Friday that Obama addressed policing issues as the rapidly evolving situation continued to command his attention in Warsaw, where he's attending a two-day NATO Summit with leaders of the military alliance. Before the summit, he also met with European Council President Donald Tusk and European Commission President Jean-Claude Juncker, focusing largely on the impact that the United Kingdom's vote to leave the European Union would have on the rest of the continent.

In his statement to reporters just after arriving at the summit shortly after midnight Warsaw time, and before the Dallas protests ended into violence, Obama said all Americans should be troubled by the videotaped police shootings of African-American men in Louisiana and Minnesota this week.

But even then, Obama was careful to acknowledge police officers who had lost their lives.

"There are times when these incidents occur, and you see protests and you see vigils. And I get letters — well-meaning letters sometimes — from law enforcement saying, how come we’re under attack? How come not as much emphasis is made when police officers are shot?" Obama said before the Dallas officers were shot. "And so, to all of law enforcement, I want to be very clear: We know you have a tough job. We mourn those in uniform who are protecting us who lose their lives. On a regular basis, I have joined with families in front of Capitol Hill to commemorate the incredible heroism that they’ve displayed. I’ve hugged family members who’ve lost loved ones doing the right thing. I know how much it hurts."

Obama, angered by police shootings, calls for elimination of racial bias