President Obama called the attack on police officers in Dallas Thursday night a "vicious, calculated and despicable" attack on law enforcement.

Twelve officers patrolling a protest against police killings were shot by snipers, five of them fatally, Dallas Mayor Mike Rawlings said. Several suspects were in custody. Two civilians were also shot, one of them in the leg.

Speaking at a NATO summit in Warsaw, Poland, Mr. Obama said he had spoken with Dallas Mayor Mike Rawlings to convey the "deepest condolences" of the American people and offer Dallas any assistance it needs in the wake of the attack.

Get Breaking News Delivered to Your Inbox

The president said he told Rawlings he was "horrified" at what had happened and called the motivations of the snipers "twisted."

"There is no possible justification for these kinds of attacks or any violence against law enforcement," Mr. Obama added.

The president observed that the attack was a wrenching reminder of the sacrifices made by law enforcement personnel.

He said the FBI is in touch with Dallas authorities to help in the investigation.

The attack came at the end of a peaceful demonstration -- one of several in cities nationwide -- that followed fatal police shootings in Louisiana and Minnesota earlier this week, the latest sparking outrage about police violence against civilians.