The 20-minute attack at Tree of Life Congregation in the Squirrel Hill neighborhood 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 offenses. It wasn't immediately known if Bowers has an attorney to speak on his behalf.
Police said "several" people were killed. Six were wounded, including the four police officers, said Wendell Hissrich, the Pittsburgh public safety director.
"It is a very horrific crime scene. It was one of the worst that I've seen. It is very bad," Hissrich said.
The attack took place during a baby naming ceremony, according to Pennsylvania Attorney General Josh Shapiro. It was unknown whether the attack harmed the baby.
The synagogue is located at the intersection of Wilkins and Shady avenues. The tree-lined residential neighborhood of Squirrel Hill, about 10 minutes from downtown Pittsburgh, is the hub of Pittsburgh's Jewish community.
At least until the suspect was taken into custody, the neighborhood and all synagogues in the city were in a lockdown, with people ordered to remain indoors.
President Donald Trump called the shooting "far more devastating than anyone thought," saying "it's a terrible thing what's going on with hate in our country."
But Trump said the outcome would have been different if the synagogue had an armed guard.
"They didn't have any protection," he told reporters at Joint Base Andrews, Maryland.
Offering a different take, Pennsylvania Democrat Gov. Tom Wolf, a Democrat, called the shooting an "absolute tragedy" in a statement that made reference to calls for tighter gun control laws.
"We must all pray and hope for no more loss of life," Wolf said. "But we have been saying "this one is too many" for far too long. Dangerous weapons are putting our citizens in harm's way."
World Jewish Congress President Ronald S. Lauder called the shooting "an attack not just on the Jewish community, but on America as a whole."
In 2010, Tree of Life Congregation - founded more than 150 years ago - merged with Or L'Simcha to form Tree of Life (asterisk) Or L'Simcha.
The synagogue is a fortress-like concrete building, its facade 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 guests.
Jeff Finkelstein of the Jewish Federation of Greater Pittsburgh said local synagogues have done "lots of training on things like active shooters, and we've looked at hardening facilities as much as possible."
"This should not be happening, period," he told reporters at the scene. "This should not be happening in a synagogue."
Just three days before the shooting, Rabbi Jeffrey Myers posted a column on the congregation's website, noting that people make time to attend funerals, but not for life's happy occasions.
"There is a story told in the Talmud of a wedding procession and a funeral procession heading along parallel roads, with the roads intersecting," Myers wrote on Wednesday. "The question asked is: when they meet at the fork, which procession goes first, funeral or wedding? The correct answer is wedding, as the joy of the couple takes precedence. In fact, the funeral procession is to move out of sight so that their joy is not lessened."
Myers ended his column with words that now seem all too prescient.
"We value joy so much in Judaism that upon taking our leave from a funeral or a shiva house, the customary statement one makes (in Yiddish) is 'nor oyf simches' - only for s'machot," Myers wrote. "While death is inevitable and a part of life, we still take our leave with the best possible blessing, to meet at joyous events. And so I say to you: nor oyf simches!"