CHRISTCHURCH, New Zealand — Moments after dozens of people were shot dead at Al Noor Mosque in New Zealand’s third-largest city, prayers were underway at another mosque to the east, just three miles away.

Inside the Linwood Mosque, 30-year-old Faisal Sayed heard a banging sound. He and another worshiper broke prayer and rushed to look out a window.

Two congregants who had been running late to the service had been shot outside, he said. A gunman dressed in military-style clothing was headed inside, firing at worshipers.

One person was shot dead, as was a woman who had given up her spot to another congregant just before services began. A third person was shot in the shoulder. A total of seven would be slain at the Linwood Mosque.

Amid the chaos, one of the congregants confronted the attacker and grabbed his weapon, Sayed said in an interview.

“He held the rifle,” Sayed said of the man who fought back. The gunman eventually fled.

“If this guy was not there,” Sayed said, “I don’t think I would be talking to you right now.” He did not identify the man.

New Zealand remained in a collective state of shock Sunday as the reality set in of the worst mass killing in its modern history. Police Commissioner Mike Bush said the death toll rose to 50. A sense of overwhelming sadness enveloped Christchurch, a city of 388,000, as well as anger over a manifesto in which a racist extremist and outsider described plans to engineer a horrific attack, targeting a place where immigrants said they felt welcome.

“End of innocence,” said the lead headline of Christchurch’s Press newspaper Saturday, above a photo of a survivor from the Linwood Mosque, his clothes stained with blood.

“I don’t know why you would attack Christchurch,” said Anthony Chui, 25, who grew up in the city and now lives in Wellington, the capital. “You think New Zealand is one of the safest countries in the world,” said his partner, Jessica Roche, 28, a native of France.

The attacks at the two Christchurch mosques were allegedly committed by an Australian, Brenton Tarrant.

Bush said Tarrant was the sole gunman involved in both mosque shootings. He added that the death toll rose from 49 after another victim was found at the scene.

“As of last night we were able to take all of the victims out of those scenes and in doing so we have located another victim,” Bush said during a news conference Sunday morning.

Many of the victims are immigrants from the Middle East and North Africa.

At least six Pakistanis were killed in the shooting, according to Shah Mahmood Qureshi, Pakistan’s foreign minister. Jordan’s Foreign Ministry announced that five of its citizens died in the attack. Four Egyptians were killed, according to Egyptian officials.

The identities of several individuals who died are now known and include Atta Elayyan, a 33-year-old New Zealand sports representative, and Husne Ara Parvin, 42. Parvin’s nephew, Mahfuv Chowdhury, told the Daily Star of Bangladesh that she died after trying to shield her husband, who uses a wheelchair, from bullets.

Also among those killed was 14-year-old Hamza Mustafa, a Syrian refugee who arrived in New Zealand only a few months ago, according to the Syrian Solidarity Network.

Three Turkish citizens also died, President Recep Tayyip Erdogan announced. And at least one Palestinian was killed, according to a statement from Izzat Ab-dulhadi, the Palestinian ambassador to Australia and New Zealand.

As of Sunday morning, 34 people remained hospitalized, 12 in critical condition, hospital officials said.

The wounded ranged in age from a toddler — a 2-year-old boy — to the elderly. A 4-year-old girl in critical condition was transferred to a hospital in Auckland, the nation’s largest city, said Greg Robertson, Canterbury District Health Board’s chief of surgery, at a news conference.

Victims were struck in the chest, abdomen, pelvis and head, Robertson said.

A manifesto written under Tarrant’s name said he was a 28-year-old white supremacist out to avenge attacks in Europe perpetrated by Muslims, and had come to New Zealand to plan and train for the attack.

The New Zealand Herald reported that Tarrant smirked at journalists as he was photographed in court, where he was charged with a single count of murder Saturday. More charges are expected. The judge ordered media organizations to pixelate photographs of the suspect to preserve his rights for a fair trial.

Prime Minister Jacinda Ardern said Tarrant had traveled around the world, with sporadic periods of time spent in New Zealand. He had been based in Dunedin, a city 200 miles southwest of Christchurch.

Tarrant had no criminal history in New Zealand or Australia, nor had he been on any watch lists in the two countries, Ardern said.

Two other suspects, a man and a woman, were arrested after the shootings. The woman has since been released without charge and the man has been charged with firearm offenses. Bush said the suspects were not linked to the gunman.

A fourth person was detained by police and later released. Sayed said that person was the hero who grabbed the gunman’s weapon at the Linwood Mosque.

The prime minister said there were five guns used by the suspect, including two semiautomatic weapons and two shotguns. Ardern also said an unspecified lever-action firearm was found.

Tarrant received a Category A gun license in 2017 that allowed him to legally acquire the guns he had, Ardern said.

Police said Tarrant used a modified weapon that allowed him to discharge bullets more quickly.

“That will give you an indication of why we need to change our gun laws,” Ardern said. She didn’t provide specifics on what she would propose.

Police responded immediately to calls reporting the attack, and the suspect was in custody 36 minutes later, Ardern said. Two other firearms were discovered in his car, she added: “It absolutely was his intention to continue with his attack.”

Attempts were being made to bury the dead as soon as possible, in accordance with Muslim tradition, but Abdirisak Sheikh, 28, who survived the shooting at Linwood Mosque and had close friends at Al Noor Mosque, said Saturday afternoon that the bodies of some of the dead still lay where they were shot.

Having been warned by authorities against meeting at mosques until further notice, Muslims have had to gather at homes and at the hospital, sharing tears and offering hugs and embraces.

Sue Naidoo, 46, came with her family to pay their respects at a makeshift memorial close to Al Noor Mosque, where a police cordon kept the public away as hearses lined up to enter.

By midday Saturday, the memorial of bouquets, stocked with pink hydrangeas and white lilies, had grown, topped with a sign that said, “This is not NZ.”

Before the attacks, Naidoo said, there was no need for immigrants to be afraid. She and her family, who are Hindu, moved here from South Africa a year ago.

“We were looking for a safer place to bring up our children, and that’s what we were expecting, and that’s what we lived — for a year,” Naidoo said, her eyes filling with tears. “And suddenly out of the blue, it was this. And it was too close to home, and too much to handle.”

Yong Kuk Kim, a 62-year-old cab driver who moved to New Zealand from South Korea decades ago, said the attack made him afraid. But he emphasized that the suspect is an outsider.

Kim said that New Zealand is welcoming toward immigrants and that he moved here so his children could get a good education. “No racism here,” Kim said. “This is a safe place.”

Sayed, the worshiper at Linwood Mosque who survived the attack, said New Zealand Muslims like him often thought they were safer here than in countries like the United States.

“People have Islamophobia in the U.K. and the U.S., and other places,” said Sayed, a native of India who moved to Christchurch a decade ago and is a hotel general manager.

Here, “you have a prime minister who occasions to celebrate with Muslims, to express that we are all together.” He cited her visit Saturday to Christchurch — talking to community leaders at a refugee center, meeting with families and friends of shooting victims who had gathered at a college, and stopping by the hospital.

“This shows and passes the message to all of the country and the world that we are not a country that is built on race, creed, religion. We are a country based on aroha that’s the values we have: compassion, love and humanity,” Sayed said, referring to a word in the Maori language, spoken by the indigenous people of New Zealand.

Some were furious at Silicon Valley giants Facebook and YouTube, a subsidiary of Google, for failing to halt the spread of a video that broadcast the massacre via Facebook Live from a camera mounted on the helmet the gunman wore.

Facebook removed the video after being alerted by New Zealand police. A company spokesman, Benjamin McConaghy, said he was unable to immediately provide details on how long it took for employees to make the change. The suspect’s Facebook and Instagram accounts were also taken down.

Facebook is working to prevent related videos and praise for the shooter or crime from appearing on its sites, Mia Garlick, a director of policy for Facebook in New Zealand and Australia, said in a statement.

Facebook and other social media companies have struggled to manage inappropriate and violent footage on their sites as more users upload massive amounts of video each day. The companies have hired moderators and beefed up their technology to flag videos, but still some slip through the cracks.

YouTube said in a tweet it was “working vigilantly to remove any violent footage.”

Meanwhile, public events across New Zealand were canceled and some restaurants remained closed for a second night Saturday in Christchurch. A Bangladesh cricket team that had been set to play Saturday in Christchurch returned home instead. Many team members were en route to Al Noor Mosque for Friday prayers just before the shooting began, local reports said.

Christchurch is the dominant urban center on the nation’s South Island, which is mostly known for its agriculture, with a focus on wool, grapes, dairy, timber, coal and tourism. Christchurch got its start in the 1840s as a trading center for farmers.

The city is becoming increasingly diverse, according to government statistics, with the proportion of the population that is white projected to decline in the next two decades from 85% to 76%, while the proportions of Asian, Maori and Pacific ethnic groups are expected to climb. About 48% of the city is Christian; 45% have no religion. Muslims make up about 0.8% of the population, behind Buddhists (1.3%) and Hindus (1%).

A magnitude 6.3 earthquake struck directly under the city in 2011, leaving many sections of its central business district in ruins and killing 185, mostly from the collapse of brittle concrete and aging brick buildings.

A memorial sits in front of the site where a television station building collapsed, with 185 chairs — one representing each victim.

One visitor wrote in a guest register for the memorial that more chairs should be added for the shooting victims.

“God will shed a tear to what happened today, since we are all his children,” the visitor wrote.