A gunman broadcast live footage on Facebook of the attack on one mosque in the city of Christchurch, mirroring the carnage played out in video games, after publishing a "manifesto" in which he denounced immigrants, calling them "invaders".
New Zealand was placed on its highest security threat level, Ardern said, adding that four people taken into custody held extremist views but had not been on any police watchlists.
Worshippers, possibly dead or wounded, lay huddled on the floor of the mosque, the video showed. Reuters was unable to confirm the authenticity of the footage.
One man who said he was at the Al Noor mosque told media the gunman was white, blond and wearing a helmet and a bulletproof vest. The man burst into the mosque as worshippers were kneeling for prayers.
"He had a big gun ... he came and started shooting everyone in the mosque, everywhere," said the man, Ahmad Al-Mahmoud. He said he and others escaped by breaking through a glass door.
Radio New Zealand quoted a witness inside the mosque saying he heard shots fired and at least four people were lying on the ground and "there was blood everywhere".
Prime Minister Jacinda Ardern condemned what she called "an extraordinary and unprecedented act of violence".
"This is one of New Zealand's darkest days," she said.
Neither Ardern nor police gave a casualty toll.
New Zealand's Police Commissioner Mike Bush said four people - three men and a woman - had been taken into custody but it was not clear if the gunman was among them or if other people were involved.
Bush also said it should not be assumed the attack was isolated to Christchurch. "At this point in time we should never make assumptions," he said.
Bush also said IEDs, improvised explosive devices, were found with a vehicle they stopped.
The online video footage, which appeared to have been captured on a camera strapped to the gunman's head, showed red petrol canisters in the back of his car, along with weapons.
All mosques in New Zealand had been asked to shut their doors, police said.
The Bangladesh cricket team was arriving for Friday prayers when the shooting occurred but all members were safe, a team coach told Reuters.
The foreign minister of Indonesia, which has the world's biggest Muslim population, condemned the shooting.
Muslims account for just over 1 percent of New Zealand's population, a 2013 census showed.
"Many of those who would have been affected by this shooting may be migrants to New Zealand," Ardern said.
"They may even be refugees here. They have chosen to make New Zealand their home and it is their home ... they are us. The persons who has perpetuated this violence against us ... have no place in New Zealand."
The online footage showed the gunman driving as music played in his vehicle. After parking, he took two guns and walked a short distance to the entrance of the mosque.
He then opened fire. Over the course of five minutes, he repeatedly shoots worshippers, leaving well over a dozen bodies in one room alone. He returned to the car during that period to change guns, and went back to the mosque to shoot anyone showing signs of life.
The video shows the gunman driving off at high speed and later firing at parked cars and a building. Police said the second mosque attacked was in the suburb of Linwood, but gave no details.
Another unconfirmed video taken by someone else appeared to show police apprehending the gunman by the side of a road.
The Bangladesh cricket team is in Christchurch to play New Zealand in a third cricket test starting on Saturday.
"They were on the bus, which was just pulling up to the mosque when the shooting begun,â€ Mario Villavarayen, strength and conditioning coach of the Bangladesh cricket team, told Reuters in a message. "They are shaken but good.â€
The third cricket test was cancelled, New Zealand Cricket said later.
Violent crime is rare in New Zealand and police do not usually carry guns.