WELLINGTON, New Zealand — At least 49 people were killed at two mosques in Christchurch, New Zealand, on Friday, in a horrific and methodical afternoon slaughter, part of which was broadcast live on the internet after the publication of a white supremacist manifesto online.

The massacre, which Jacinda Ardern, New Zealand’s prime minister, condemned as a terrorist attack and called “an extraordinary and unprecedented act of violence,” interrupted a day of prayer for a small immigrant community in the nation’s third-largest city and shook a country with little history of mass shooting.

Harrowing first-person footage, apparently from a camera worn by a gunman as he attacked the Al Noor Mosque in the center of the city, was streamed on Facebook, a grim development in terrorism that raised questions about the ability of global tech companies to block violent content from spreading around the world.

[Follow our live briefing here.]

Facebook said it quickly shut down the account, but a 17-minute video showing a man dressed in black shooting at fleeing worshipers and into piles of bodies with a semiautomatic rifle circulated widely online. In addition to those killed, at least 20 were injured, the authorities said.

The police said a man in his late 20s was arrested and charged with murder but declined to identify him. The police also said they seized several weapons and found two explosive devices on a vehicle.

“This is and will be one of New Zealand’s darkest days,” Ms. Ardern said at a news conference.

Schools in the downtown area were locked down for hours after the attacks as the police tried to determine whether the gunman acted alone. The authorities urged residents to stay indoors, asked mosques to close and cleared nearby Cathedral Square, where people had gathered as part of worldwide protests to demand action on climate change.

New Zealand’s police commissioner, Mike Bush, said three other individuals found near the scene with weapons were also taken into custody, though investigators later said that one probably had nothing to do with the attacks.

The shootings were first reported at about 1:40 p.m., around the time of the midday Friday prayer, when the Al Noor Mosque and the Linwood Mosque, about three miles east, would be most busy. Minutes earlier the manifesto appeared online.

The document named both mosques, and links to it were posted on Twitter and 8chan, an online forum known for hosting message boards with extremist right-wing discussions. The 8chan post included a link to what appeared to be the gunman’s Facebook page, where he said he would soon broadcast live video of the attack.

Ms. Ardern said that many of the victims were most likely migrants to New Zealand or refugees.

“Christchurch was the home of these victims,” she said. “For many this may not have been the place they were born. For many, New Zealand was their choice, the place that they chose to come to and committed themselves to, the place they chose to raise their families.”

She added that New Zealand was likely targeted “because we represent diversity, kindness, compassion, a home for those who share our values, refuge for those who need it.”

Nasreen Hanif, a spokeswoman for the Islamic Women’s Council of New Zealand, said people were anxious for updates and were worried that friends or family members were among the dead.

“Nobody’s answering their phones,” she said. “We don’t know if they’re at the hospital or out of reach. Some have posted that they are safe, but others have not.”

Ms. Hanif said the two mosques in Christchurch had asked for help from Muslims across the country to arrange the 49 funerals they would need to plan.

Historians say Muslims have lived in New Zealand for more than 150 years, but the population has grown with immigration from war-torn countries like Iraq and Afghanistan in the 1990s and 2000s. In a country of nearly five million people, though, only about 46,000 identified as Muslim in the 2013 census.

The video of the attack, which appeared to be recorded on a helmet camera, showed the gunman driving to the mosque and then opening fire even before he entered the building. For nearly two minutes, he shoots at fleeing worshipers before he leaves, runs back to his car and swaps weapons.

He then is seen re-entering the mosque and opening fire again, methodically moving from room to room and shooting into piles of bodies slumped on the green carpets. Several victims can be seen in the footage, many lying on top of one another motionless in a corner of the room.

After another few minutes, he leaves again, gets in his vehicle and drives away, pausing occasionally to fire at pedestrians and talking to himself throughout.

“There wasn’t even time to aim, there was so many targets,” he says at one point.

The police in New Zealand said they were working to remove the video from the internet and urged people not to share it.

Facebook said it was alerted by the police shortly after the livestream started. “We quickly removed both the shooter’s Facebook and Instagram accounts and the video,” Mia Garlick, a Facebook representative, said in a statement. “We’re also removing any praise or support for the crime and the shooter or shooters as soon as we’re aware.”

Felix Kjellberg, a Swedish Youtube star known as PewDiePie, said he felt “absolutely sickened” that the gunman had endorsed him in the video. Mr. Kjellberg has been criticized for anti-Semitism over skits that he called satirical.

The video and Twitter posts showed weapons covered in the names of past military generals and men who have recently carried out mass shootings.

The author of the manifesto identifies himself as a 28-year-old man born in Australia. He listed his white nationalist heroes, described his animosity toward Muslims and immigrants, and said he chose to use guns in the attacks to stir discord in the United States around the Second Amendment.

Aman Singh, 26, who works at a convenience store close to the Al Noor Mosque, said he hid after hearing gunshots and seeing people stream past, bloody and crying.

“My really good friend goes there,” he said, adding that he had not been able to confirm the friend’s whereabouts.

Mohammad Isam, a Bangladeshi journalist, posted a video of members of Bangladesh’s national cricket team who he said escaped the attack.

Christchurch, with about 388,000 residents, is the biggest city on New Zealand’s South Island, hugging the Pacific Ocean coast.

There hasn’t been a mass shooting in New Zealand since 1990, when a man killed 13 people, including two 6-year-olds, after a dispute with his neighbor in the seaside town of Aramoana.

That shooting led to tightened gun laws, including restrictions on “military style semiautomatic weapons.”

Gun owners must be licensed, a process that includes a review of criminal activity and mental health, attendance at a safety program, an explanation of how the gun would be used, a residence visit to ensure secure storage, and testimonials from relatives and friends.

Murders are rare in New Zealand, and gun homicides even rarer. There were 35 murders countrywide in 2017. Since 2007, gun homicides have been in the single digits each year except 2009, when there were 11.

But there are plenty of guns. There were 1.2 million registered firearms in a country of 4.6 million people in 2017, according to the Small Arms Survey, a Swiss nonprofit.