Five police officers were fatally shot and six wounded in one of the worst shootings of police in recent U.S. history, by snipers who targeted them during rallies in Dallas to protest against the fatal shooting of two black men by police this week.

Dallas Police Chief David Brown told a news conference that two snipers in elevated positions shot 11 officers, killing three, in what appeared to be a coordinated attack. A fourth officer died, police said later on Twitter. At least one more was in surgery. Some of the victims were shot in the back.

Police said one suspect whom they had engaged in a shootout had been arrested and a bomb squad unit was investigating a suspicious package found near the suspect's location.

 A second "person of interest" had turned himself in, they added, though there was no word on the arrest of a possible second sniper.

"Our worst nightmare has happened," Mike Rawlings, mayor of the Texas city, told a news conference. "It is a heartbreaking moment for the city of Dallas."

Television footage showed a heavy police presence, with officers taking cover behind vehicles on the street.

The shooting happened as largely peaceful protests unfolded around the United States after the shooting of Philando Castile, 32, by police near St. Paul, Minnesota, late on Wednesday. His girlfriend posted live video on the internet of the bloody scene minutes afterward, which was widely viewed.

Castile's death occurred within a day of the shooting of Alton Sterling, 37, in Baton Rouge, Louisiana. Sterling was killed during an altercation with two white police officers. Graphic video of that incident caused an outcry on social media.

"Our thoughts and prayers are with the Dallas law enforcement community and the Dallas Area Rapid Transit officers killed and injured this evening," Governor Greg Abbott said in a statement.

In Chicago, protesters shut down a stretch of the Dan Ryan Expressway - one of Chicago's main arteries - for about 10 minutes on Thursday.

In New York, several hundred protesters blocked traffic in Times Square in the heart of Manhattan, chanting "Hands up, don't shoot." More than a dozen arrests were made, the New York Police Department said.

In St. Paul, about a thousand people gathered outside the governor's mansion, chanting "Hey hey, ho ho, those killer cops have got to go," and other slogans.

Minnesota Governor Mark Dayton made a brief appearance in an attempt to quell the crowd. He said earlier a state investigation was already under way.

"Would this have happened if the driver and the passengers were white? I don’t think it would have," Dayton told reporters, speaking of the Castile shooting.

"So I'm forced to confront that this kind of racism exists, and it's incumbent upon all of us to vow and ensure that it doesn't happen and doesn't continue to happen," he said.

State investigators later identified Minneapolis area police officer Jeronimo Yanez as the patrolman who fatally shot Castile during a traffic stop.

"Black lives matter"

"We had an exchange of gunfire with the suspect. We saw no other option but to use our bomb robot," Dallas Police Chief David Brown told reporters at City Hall.

"The suspect said he was upset about Black Lives Matter," said Brown, who is black. "He said he was upset about the recent police shootings. The suspect said he was upset at white people. The suspect stated that he wanted to kill white people, especially white officers."

In talking with police negotiators, the suspect said he was not affiliated with any group and acted alone, according to Brown.

Quinyetta McMillon, who had a child with Alton Sterling, the black man slain by police in Baton Rouge, Louisiana, earlier this week, condemned the Dallas attack in a statement.

"We wholeheartedly reject the reprehensible acts of violence that were perpetrated against members of the Dallas Police Department," McMillon said. "Regardless of how angry or upset people may be, resorting to this kind of sickening violence should never happen and simply cannot be tolerated."

A Twitter account describing itself as representing the Black Lives Matter movement sent the message: "Black Lives Matter advocates dignity, justice and freedom. Not murder."

With Thursday's attack, 26 police officers have been shot and killed in the United States so far this year, according to the National Law Enforcement Officers Memorial Fund. That is up 44 percent from the 18 officers slain in the same period in 2015, the group said.

Some of the largest police forces in the United States were on high alert on Friday, following the attacks in Dallas, with departments in New York and Boston ordering officers to patrol in pairs.

 "RACIAL DISPARITIES" - OBAMA

U.S. President Barack Obama described the killings as tragedies.

"All of us as Americans should be troubled by these shootings, because these are not isolated incidents. They're symptomatic of a broader set of racial disparities that exist in our criminal justice system," he said after arriving in Poland for a NATO summit.

The use of force by police against African-Americans in cities from Ferguson, Missouri, to Baltimore and New York has sparked periodic and sometimes violent protests in the past two years and has spawned the Black Lives Matter movement.

Anger has intensified when the officers involved in such incidents have been acquitted in trials or not charged at all.

"I was already fuming when I woke up this morning over Baton Rouge, but for it to happen here again just pushed me right over the edge," said truck driver Thomas Michaels, 42, who was among the protesters in St. Paul.

"We live in a racist society where black lives don't matter, my kids lives don't matter and I'm sick of it. I don't even know if it can be fixed," he said.

Another protester, retail worker Tanya McDonald, 28, said: "What gets me is how many people are failing to see that this is happening almost every day. We're dying, we're being killed off by people hiding behind a badge and no one's doing anything to stop it."

The Washington Post said Castile was at least the 506th person and 123rd black American shot and killed by police so far in 2016, according to a database it has set up to track such deaths