At a news conference at the NATO summit in Poland, President Obama talked about the ambush that left five Dallas police officers dead on Thursday during a demonstration. Obama plans to visit Dallas early next week. (Reuters)

At a news conference at the NATO summit in Poland, President Obama talked about the ambush that left five Dallas police officers dead on Thursday during a demonstration. Obama plans to visit Dallas early next week. (Reuters)

After a crushing week of attacks, protests and anger, President Obama touched on the values that unite Americans before diving headlong into the debate over guns, one of the most divisive issues of his presidency.

The president, speaking on Saturday at the NATO summit here, suggested that the licensed gun in the car of Philando Castile, who was shot by police in Minnesota during a routine traffic stop, had contributed to the tragedy there. Castile died as his girlfriend live-streamed video of him bleeding to death while an armed police officer stood a few feet away.

“We don’t know what happened, but we do know that there was a gun in the car that apparently was licensed, but it caused in some fashion those tragic events,” Obama said of Castile’s shooting.

[The NRA’s internal revolt over Philando Castile]

Castile’s death and the killing of Alton Sterling by police in Baton Rouge set off waves of protests across the United States last week. At one of those marches in Dallas, a gunman killed five police officers who were providing security at the march.

President Obama urged Americans not to see the country as being riven into opposing groups, seeking to soothe raw emotions after a "painful" week of deadly shootings. (Reuters)

“This has been a tough week, first and foremost for the families of those who have been killed, but also for the entire American family,” Obama said at a news conference here.

Obama had been scheduled to return to Washington on Monday after two days in Spain, but he decided to curtail his trip and come back Sunday night after a meeting with that country’s interim prime minister and a visit with U.S. military personnel. He is expected to visit Dallas early next week.

Obama emphasized in his remarks to reporters that the United States “is not as divided as some have suggested,” and he noted that Americans of “all races and backgrounds” were outraged by the attacks on police.

On the gun issue, he said the polarization in the country pitted “a very intense minority” against the “majority of Americans who actually think we could be doing better when it comes to gun safety.”

The president described the prevalence of guns in some poor neighborhoods as a contributing factor to the broader tensions between police and the people they are supposed to protect. He cited the deadly protest in Dallas on Thursday as an example.

[Graphic: How the Dallas attack unfolded]

Obama said some of the protesters in Dallas, a large city in a state where people can openly carry weapons with a license, were armed during the march.

At a news conference at the NATO summit in Poland, President Obama talked about the need for gun control in the aftermath of the attack that killed five Dallas police officers during a peaceful protest. (Reuters)

“Imagine if you are a police officer and you are trying to sort out who is shooting at you and there are a bunch of people who have got guns on them,” he added.

He vowed to continue talking about the need for gun reforms, even in the aftermath of the tragedies.

“We can’t just ignore that and pretend that’s somehow political or the president is pushing his policy agenda,” Obama said. “It is a contributing factor. Not the sole factor, but a contributing factor to the broader tensions that arise between police and the communities that they serve. And so we have to talk about that.”

Although Dallas and violence at home became the public focus of Obama’s trip to Warsaw, the president said Saturday that NATO leaders had taken important steps to address security far beyond U.S. borders, with deployments to Eastern Europe to defend against Russia and to the Mediterranean to handle migrant flows, as well as an extension of the Afghanistan mission to bolster shaky security there.

[NATO will expand security patrols in Mediterranean in response to ISIS threat]

“We’re moving forward with the most significant reinforcement of our collective defense any time since the Cold War,” Obama said. At the NATO summit, Obama announced plans for a U.S.-led battalion of about 1,000 troops that will deploy to Poland. Three other battalions will be sent to Estonia, Latvia and Lithuania.

As he heads toward his final months in office, Obama acknowledged a wide range of challenges to global security that will extend far into the future. The Islamic State’s territorial losses in Iraq and Syria in recent weeks could spur the group to launch global terrorist attacks, he said.

Obama praised the post-World War II legacy of NATO and other global institutions that have prevented wars between states and set off a period of unprecedented prosperity. He suggested that Britain’s decision to split from the European Union could hurt the global economy and said he was counseling Britain and the E.U. to split in a way that would cushion the economic blow.

Speaking of the legacy of global institutions such as the E.U., NATO and the United Nations, he said, “We should be proud of that and preserve it.”

But, he said, threats such as the Islamic State and al-Qaeda, which do not obey territorial bounds, could not be definitively defeated in traditional ways. Such groups guarantee that the United States will be waging at least low-level combat for years, possibly decades.

Because groups like the Islamic State are “non-state actors, it’s very hard for us ever to get the satisfaction of MacArthur and the emperor meeting and a war being officially over,” Obama said, referring to the U.S. general and Japanese leader at the end of World War II.