PITTSBURGH -- A gunman who's believed to have spewed anti-Semitic slurs and rhetoric on social media barged into a Pittsburgh synagogue on Saturday and opened fire, killing 11 people in one of the deadliest attacks on Jews in U.S. history.

The 20-minute attack at Tree of Life Congregation in the Squirrel Hill neighbourhood left six others wounded, including four police officers who dashed to the scene, authorities said.

The suspect, Robert Bowers, traded gunfire with police and was shot several times. Bowers, who was in fair condition at a hospital, was charged late Saturday with 29 federal counts, including hate crimes and weapons offences. It wasn't immediately known if Bowers had an attorney to speak on his behalf.

"Please know that justice in this case will be swift and it will be severe," Scott Brady, the chief federal prosecutor in western Pennsylvania, said at a news conference, characterizing the slaughter as a "terrible and unspeakable act of hate."

The mass shooting came amid a rash of high-profile attacks in an increasingly divided country, one day after a Florida man was arrested and charged with mailing a series of pipe bombs to prominent Democrats and little more than a week before the midterm elections.

The killings also immediately reignited the longstanding national debate about guns: U.S. President Donald Trump said the outcome might have been different if the synagogue "had some kind of protection" from an armed guard, while Pennsylvania's Democratic Gov. Tom Wolf noted that once again "dangerous weapons are putting our citizens in harm's way."

Trump ordered flags at federal buildings throughout the U.S. to be flown at half-staff in "solemn respect" for the shooting victims. He said he planned to travel to Pittsburgh, but offered no details.

Authorities say that just before 10 a.m., Bower entered the large synagogue with an assault-style rifle and three handguns. Three separate congregations were conducting Sabbath services in different areas of the large building, according to Michael Eisenberg, the immediate past president of the Tree of Life. The Pennsylvania attorney general's office said it was told by victims that a brit milah -- a ritual circumcision ceremony at which a baby boy also receives his Hebrew name -- was also taking place, though law enforcement officials later said no children were among the dead or wounded.

"It is a very horrific crime scene," said a visibly moved Wendell Hissrich, the Pittsburgh public safety director. "It's one of the worst that I've seen."

The survivors included Daniel Leger, 70, a nurse and hospital chaplain who was in critical condition after undergoing surgery, his brother, Paul Leger, told the Pittsburgh Post-Gazette. Daniel Leger was scheduled to lead a service Saturday morning, he said.

The mass shooting raised immediate alarm in Jewish communities around the country. Authorities in New York City, Chicago and elsewhere increased security at Jewish centres.

Bob Jones, head of the FBI's Pittsburgh office, said that worshippers "were brutally murdered by a gunman targeting them simply because of their faith," though he cautioned the shooter's full motive was not yet known.

Bowers, who had no apparent criminal record, expressed virulently anti-Semitic views on a social media site called Gab, according to an Associated Press review of an archived version of the posts made under his name. The cover photo for his account featured a neo-Nazi symbol, and his recent posts included a photo of a fiery oven like those used in Nazi concentration camps used to cremate Jews during World War II.

Other posts referenced false conspiracy theories suggesting the Holocaust -- in which an estimated 6 million Jews perished -- was a hoax. He wrote of a Jewish "infestation," using a slur for Jews.

Gab confirmed Bowers had a profile on its website, which is popular with far-right extremists.

Before the shooting, the poster believed to be Bowers also wrote that "HIAS likes to bring invaders in that kill our people. I can't sit by and watch my people get slaughtered. Screw your optics, I'm going in."

HIAS is a non-profit group that helps refugees around the world find safety and freedom. The organization says it is guided by Jewish values and history.

Jonathan Greenblatt, chief executive officer of the Anti-Defamation League, said the group believes Saturday's attack was the deadliest on the Jewish community in U.S. history.

"Our hearts break for the families of those killed and injured at the Tree of Life Synagogue, and for the entire Jewish community of Pittsburgh," Greenblatt said.

Israeli Prime Minister Benjamin Netanyahu said he was "heartbroken and appalled" by the attack.

"The entire people of Israel grieve with the families of the dead," Netanyahu said. "We stand together with the Jewish community of Pittsburgh. We stand together with the American people in the face of this horrendous anti-Semitic brutality. And we all pray for the speedy recovery of the wounded."

Thousands of people, some holding candles, gathered for a vigil in the Squirrel Hill neighbourhood on Saturday night in honour of the victims, whose names were not immediately released. A chant of "vote, vote, vote" broke out during the emotional gathering. Some attendees blamed the shooting on the nation's political climate, and said they took little solace in the planned visit by Trump.

At a political rally in Murphysboro, Illinois, Trump said "the evil anti-Semitic attack is an assault on all of us."

The president -- who, at times, has been accused by critics of failing to adequately condemn hate, such as when he blamed "both sides" for the violence at a Charlottesville, Virginia, white supremacist rally in 2017 -- said that anti-Semitism must be "confronted and condemned everywhere it rears it very ugly head." He called for the imposition of the death penalty for "crimes like this."

The synagogue is located in the tree-lined residential neighbourhood of Squirrel Hill, about 10 minutes from downtown Pittsburgh and the hub of Pittsburgh's Jewish community. The facade of the fortress-like concrete building is punctuated by rows of swirling, modernistic stained-glass windows illustrating the story of creation, the acceptance of God's law, the "life cycle" and "how human-beings should care for the earth and one another," according to its website. Among its treasures is a "Holocaust Torah," rescued from Czechoslovakia.

Its sanctuary can hold up to 1,250 people.

Eisenberg, the former synagogue president, said officials at Tree of Life had not gotten any threats that he knew of before the shooting. But he said security was a concern, and the synagogue had started working to improve it.

Chuck Diamond, a former rabbi at the synagogue who retired more than a year ago, said the building is locked during the week, and is outfitted with security cameras. "But on Sabbath it's an open door," he said.

"You know, you're always worried that something would happen," said Myron Snider, head of the cemetery committee for New Light Congregation, which meets at Tree of Life. Snider just got out of the hospital on Thursday and missed Saturday's service.

"But you never dream that it would happen like this," Snider added. "Just never ever dream that it would happen like this."

Associated Press writers Eric Tucker and Michael Balsamo in Washington, Claudia Lauer in Philadelphia, Gene Puskar in Pittsburgh, Marc Levy in Harrisburg and Allen G. Breed in Raleigh, N.C., and Michael Kunzelman in Silver Spring, Maryland, contributed to this report.

Watching the events unfolding in Pittsburgh, Pennsylvania. Law enforcement on the scene. People in Squirrel Hill area should remain sheltered. Looks like multiple fatalities. Beware of active shooter. God Bless All! — Donald J. Trump (@realDonaldTrump) October 27, 2018

Events in Pittsburgh are far more devastating than originally thought. Spoke with Mayor and Governor to inform them that the Federal Government has been, and will be, with them all the way. I will speak to the media shortly and make further statement at Future Farmers of America. — Donald J. Trump (@realDonaldTrump) October 27, 2018

ALERT: There is an active shooter in the area of WILKINS and Shady. Avoid the area. More info will be released when it is available. — Pgh Public Safety (@PghPublicSafety) October 27, 2018

“Canadians’ hearts are with the Jewish community in Pittsburgh today, as they endured a horrific anti-Semitic attack while at prayer. May the families of those murdered be comforted, and may the injured recover quickly and fully.”—Prime Minister Justin Trudeau — CanadianPM (@CanadianPM) October 27, 2018

I share the deep anguish in the Jewish community everywhere as we witness the horrific violence against those attending synagogue in Pittsburgh this morning. The love of all decent people surrounds the victims and their families. If Canada can help, we will. — Ralph Goodale (@RalphGoodale) October 27, 2018