Mass shootings at two mosques full of worshippers attending Friday prayers killed 40 people on what the prime minister called “one of New Zealand’s darkest days,” as authorities detained four people and defused explosive devices in what appeared to be a carefully planned racist attack.

Prime Minister Jacinda Ardern said the events in Christchurch represented “an extraordinary and unprecedented act of violence” and acknowledged many of those affected may be migrants and refugees. In addition to the dead, she said more than 20 people were seriously wounded.

“It is clear that this can now only be described as a terrorist attack,” Ardern said.

Police took three men and a woman into custody after the shootings, which shocked people across the nation of 5 million people. While there was no reason to believe there were more suspects, Ardern said the national security threat level was being raised to the second-highest level.

He said he helped about five people recover in his home. He said one was slightly injured.

“I’ve lived next door to this mosque for about five years and the people are great, they’re very friendly,” he said. “I just don’t understand it.”

A man reacts as he speaks on a mobile phone near a mosque in central Christchurch, New Zealand, Friday, March 15, 2019. Multiple people were killed in mass shootings at two mosques full of people attending Friday prayers, as New Zealand police warned people to stay indoors as they tried to determine if more than one gunman was involved.(AP Photo/Mark Baker)

He said the gunman was white and was wearing a helmet with some kind of device on top, giving him a military-type appearance.

A video that was apparently livestreamed by the shooter shows the attack in horrifying detail. The gunman spends more than two minutes inside the mosque spraying terrified worshippers with bullets again and again, sometimes re-firing at people he has already cut down.

He then walks outside to the street, where he shoots at people on the sidewalk. Children’s screams can be heard in the distance as he returns to his car to get another rifle.

The gunman then walks back into the mosque, where there are at least two dozen people lying on the ground. After walking back outside and shooting a woman there, he gets back in his car, where the song “Fire” by English rock band “The Crazy World of Arthur Brown” can be heard blasting from the speakers. The singer bellows, “I am the god of hellfire!” and the gunman drives away. The video then cuts out.

There was a second shooting at the Linwood Masjid Mosque that Ardern said killed 10 people.

This image taken from the alleged shooter’s video, which was filmed Friday, March 15, 2019, shows a gun in his vehicle in New Zealand. A witness says many people have been killed in a mass shooting at a mosque in the New Zealand city of Christchurch. Police have not described the scale of the shooting but urged people to stay indoors. (AP Photo)

Mark Nichols told the New Zealand Herald he heard about five gunshots and that a Friday prayer-goer returned fire with a rifle or shotgun.

Nichols said he saw two injured people being carried out on stretchers past his automotive shop and that both people appeared to be alive.

The man who claimed responsibility for the shooting said he came to New Zealand only to plan and train for the attack. He said he was not a member of any organization, but had donated to and interacted with many nationalist groups, though he acted alone and no group ordered the attack.

He said the mosques in Christchurch and Linwood would be the targets, as would a third mosque in the town of Ashburton if he could make it there.

He said he chose New Zealand because of its location, to show that even the most remote parts of the world were not free of “mass immigration.”

This image taken from the alleged shooter’s video, which was filmed Friday, March 15, 2019, shows him as he drives and he looks over to three guns on the passenger side of his vehicle in New Zealand. A witness says many people have been killed in a mass shooting at a mosque in the New Zealand city of Christchurch. Police have not described the scale of the shooting but urged people to stay indoors. (AP Photo)

New Zealand is generally considered to be a welcoming country for immigrants and refugees. Last year, the prime minister announced the country would boost its annual refugee quota from 1,000 to 1,500 starting in 2020. Ardern, whose party campaigned on the promise of raising the intake of refugees, dubbed the planned increase “the right thing to do.”

A cricket match between New Zealand and Bangladesh scheduled to start Saturday was canceled after the Bangladesh cricket team had a narrow escape.

Players and members of the team’s coaching staff were reportedly on their bus, approaching the Masjid Al Noor mosque in Hagley Park when the shooting broke out.

Batsman Tamim Iqbal tweeted “entire team got saved from active shooters. Frightening experience and please keep us in your prayers.”

Mass shootings in New Zealand are exceedingly rare. The deadliest in modern history occurred in the small town of Aramoana in 1990, when gunman David Gray shot and killed 13 people following a dispute with a neighbor.