Forty people were killed in shootings at two mosques in central Christchurch, New Zealand, on Friday, in what Prime Minister Jacinda Ardern labeled “a terrorist attack.”

• Officials said that four people were in custody, adding that a number of explosive devices were found attached to vehicles that they had stopped.

• A Muslim leader in New Zealand said the attack was especially shocking as it took place during Friday prayers. The police called on mosques nationally to “shut their doors” and urged people to stay away from the mosques until further notice.

• A video and manifesto that appeared to be by a gunman involved in the shooting were posted online on the day of the attack.

Two mosques are attacked

Shots were fired at the Al Noor Mosque on Deans Avenue near Hagley Park, and the Linwood Mosque was also attacked, the police said.

Ms. Ardern said in a news conference that 30 people had been killed at Al Noor Mosque and that 10 others had died at Linwood Mosque. More than 20 others who were seriously injured were being treated in the hospital, she said.

The police said that four people, including three men and one woman, had been taken into custody. Prime Minister Scott Morrison of Australia said that one of them was Australian.

Ms. Ardern described those arrested as one principal, two associates and one person not directly connected to the attacks. She said that none of them were on security watch lists.

Ms. Ardern, describing the shootings as a terrorist attack that was “well planned,” said that the country’s national security threat had been raised from low to high.

“There is heightened security so we can assure people of their safety,” she said.

The country’s police commissioner, Mike Bush, urged people not to go to mosques anywhere in New Zealand on Friday.

He also urged mosques nationally to shut their doors, advising them to “close your doors until you hear from us again.”

Calling the situation “very serious and grave,” Mr. Bush said that the police were in the process of mobilizing all national forces.

— CHARLOTTE GRAHAM-McLAY and MEGAN SPECIA

Video appears to show part of the shooting

A 17-minute video posted to social media appears to show part of the attack.

The clip, which may have been taken from a helmet camera worn by a gunman, begins behind the wheel of a car. A man, whose face can occasionally be seen in the rearview mirror, drives through the streets of Christchurch before pulling up in front of the Muslim Association of Canterbury and its adjoining mosque on Dean Avenue, beside the sprawling Hagley Park.

He then approaches the front of the mosque on foot, his weapon visible, and begins shooting at people at the entrance. What follows is a harrowing nearly two minutes of his firing on the worshipers.

At one point, the gunman exits the mosque and fires in both directions down the sidewalk before returning to his car for another gun — which, like the others, was inscribed with numbers, symbols or messages. When he re-enters the mosque, he shoots several bodies at close range.

After another few minutes, he returns to his vehicle and drives away.

“There wasn’t even time to aim, there was so many targets,” he says at one point, as the sirens of an emergency response vehicle blare in the background.

— MEGAN SPECIA and JASON BAILEY

A white-nationalist manifesto

Before the shooting, someone appearing to be the gunman publicly posted links to a white-nationalist manifesto on Twitter and the online forum 8chan. The 8chan post included a link to what appeared to be the gunman’s Facebook page, where he said he would also broadcast live video of the attack.

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

In his manifesto, he identified himself as a 28-year-old man born in Australia and listed his white nationalist heroes.

He described what he said had motivated him to carry out the attack, and said he had purposely used guns to stir discord in the United States over the Second Amendment’s provision on the right to bear arms.

He also declared himself a fascist. “For once, the person that will be called a fascist, is an actual fascist,” he wrote in the manifesto, adding that China’s “political and social values” were closest to his own.

— DANIEL VICTOR and TIFFANY MAY

Scrutiny of social media postings

Over the last 18 months, tech companies have promised to put stronger safeguards in place to ensure that violent content is not distributed through their sites, especially during breaking news events.

But those new safeguards were not enough to stop the posting of a video and manifesto believed related to Friday’s shooting across various social media channels.

A 17-minute video that included graphic footage apparently of the shooting could be found on Facebook, YouTube, Twitter and Instagram more than an hour after being posted. While both Facebook and Twitter took down pages thought to be linked to a gunman in the attack, the content that had been posted on them was already spreading rapidly through other accounts.

Dozens of versions of the video could be found through a quick search of words and names linked to a suspected gunman.

The country’s police commissioner, Mike Bush, said the social media postings “shouldn’t be in the public domain.”

In order to evade detection, people appeared to be cropping the video or posting the text of the manifesto as an image — both of which are techniques used to evade automated systems put into place by social media channels to automatically find and delete content.

Social media companies largely rely on artificial intelligence to automatically find and remove banned content. The companies have heavily invested in those systems, with Facebook reporting last year that more than 99 percent of terrorism content by the Islamic State and Al Qaeda was found and removed through artificial intelligence.

A Facebook spokeswoman offered condolences to the victims and said the company was working to stop the spread of any content in support of the attack.

“Police alerted us to a video on Facebook shortly after the livestream commenced and we quickly removed both the shooter’s Facebook and Instagram accounts and the video,” said Mia Garlick of Facebook New Zealand.

She added that the company was “also removing any praise or support for the crime and the shooter or shooters as soon as we’re aware.”

— SHEERA FRENKEL and DANIEL VICTOR

An attack during Friday prayers

Moustafa Farouk, a spokesman for the Federation of Islamic Associations of New Zealand, said it was especially shocking for Muslims that the attack occurred during Friday prayers.

“Its Friday, when we normally congregate for our prayers, so no one ever thought this would happen,” Mr. Farouk said in a telephone interview.

Mr. Farouk, who said he was on his way to Christchurch to meet with Muslims there, said he had never imagined that an attack of this kind could happen in New Zealand, which he described as a country with a “good reputation.”

“It’s one of the most peaceful countries in the world,” he added, although he said that “this kind of random act of violence will affect that image.”

— MEGAN SPECIA

‘One of New Zealand’s darkest days’

Ms. Ardern called Friday “one of New Zealand’s darkest days.”

“What has happened here is an extraordinary and unprecedented act of violence,” the prime minister said at a news conference in New Plymouth, describing the shooting as “an act that has absolutely no place in New Zealand.”

“Many of those affected may be migrants to New Zealand — they may even be refugees here,” Ms. Ardern said of the victims. “They are one of us. The person who has perpetrated these acts is not.”

“My thoughts, and I’m sure the thoughts of all New Zealanders, are with those affected and their families,” the prime minister added.

— CHARLOTTE GRAHAM McLAY

‘My really good friend goes there’

Aman Singh, who works at a convenience store close to the Deans Avenue mosque, said he had heard the gunshots on Friday afternoon, and that shortly afterward people had streamed past the shop, bloody and crying.

Mr. Singh, 26, said he knew several people who worshiped at the mosque.

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

Mr. Singh, who moved to New Zealand from India four and a half years ago, was still hiding in the store with his wife, as the police had yet to arrive at their location.

He said they would be unlikely to be able to return home anyway, as their street was cordoned off because it was close to the Linwood Mosque that was also attacked.

— CHARLOTTE GRAHAM-McLAY

Lawmaker warns against ‘knee-jerk response’

Trevor Mallard, a Labour party lawmaker and the speaker of the house, said he was evacuated from Canterbury University, where he was with several other lawmakers to attend a student protest over climate change that is part of a worldwide movement.

Mr. Mallard described the shootings as “absolutely awful and unfair,” and he urged New Zealanders against “any sort of knee-jerk response.”

“Security is constantly under review, and this will be factored in,” he said, although he added that he did not expect “massive changes in the longer term” to security at Parliament.

— CHARLOTTE GRAHAM-McLAY

Murders are rare in New Zealand, but guns aren’t

Murders are rare in New Zealand, and gun homicides even rarer. There were 35 murders countrywide in 2017. And 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 the country of 4.6 million people in 2017, according to the Small Arms Survey, a Swiss nonprofit.

A mass shooting in the New Zealand in 1990 — when a man killed 13 people, including two 6-year-olds, after a dispute with his neighbor in the seaside town of Aramoana — led directly 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.

— DANIEL VICTOR

Bangladeshi cricketers flee a mosque under siege

One of the members of Bangladesh’s national cricket team, who said he and other teammates had fled the mosque as the shooting began, tweeted about his escape.

The cricketer, Mushfiqur Rahim, thanked god for his safety and wrote: “we r extremely lucky…never want to see this things happen again….pray for us.”

The team later confirmed on its own Twitter account that all members of the national team were safe, adding that “The Bangladesh Cricket Board (BCB) is in constant contact with the players and team management.”