* 49 dead, more than 40 wounded
* Mass shootings livestreamed online
* NZ chosen as it represents "kindness, compassion" -PM
* Trump denounces "horrible massacre"
A gunman shot dead 49 people and wounded more than 40 at two New Zealand mosques on Friday, some as they were kneeling at prayer, livestreaming online some of the killings in what Prime Minister Jacinda Ardern called an assault on the nation's values.
The gunman broadcast footage of the attack on one mosque in the city of Christchurch on Facebook, mirroring the carnage played out in video games, after publishing a "manifesto" in which he denounced immigrants, calling them "invaders".
The video footage widely circulated on social media, apparently taken by a gunman and posted live online as the attack unfolded, showed him driving to a mosque, entering it and shooting randomly at people inside.
Worshippers, possibly dead or wounded, lay huddled on the floor, the video showed. Reuters was unable to confirm the authenticity of the footage.
It was the worst ever mass killing in New Zealand and the country raised its security threat level to the highest, Ardern said, adding, "This can now only be described as a terrorist attack."
Police said three people were in custody including one man in his late 20s who had been charged with murder. He will appear in court on Saturday. Police have identified none of the suspects.
"We were not chosen for this act of violence because we condone racism, because we are enclave for extremism," Ardern said in a national address. "We were chosen for the fact that we are none of these things. It was because we represent diversity, kindness, compassion, a home for those who share our values.
"You have chosen us but we utterly reject and condemn you."
Police Commissioner Mike Bush said 49 people had been killed. Health authorities said 48 people were being treated for gunshot wounds, including young children.
Leaders around the world expressed sorrow and disgust at the attacks, with some deploring the demonisation of Muslims.
Police cordon off the area in front of the Masjid al Noor mosque after a shooting incident in Christchurch
Police officers cordoning a street near the mosque after a firing incident in Christchurch
US President Donald Trump condemned the "horrible massacre" in what the White House called a "vicious act of hate".
The gunman's manifesto praised Trump as "a symbol of renewed white identity and common purpose". The White House did not immediately respond to a request for comment.
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.
Forty-one people were killed at the Al Noor mosque, seven at a mosque in the Linwood neighbourhood and one died in hospital, police said. Hospitals said children were among the victims.
The visiting Bangladesh cricket team was arriving for prayers at one of the mosques when the shooting started but all members were safe, a team coach told Reuters.
Three Bangladeshis were among the dead and one was missing, the consulate said.
Shortly before the attack began, an anonymous post on the discussion site 8chan, known for a wide range of content including hate speech, said the writer was going to "carry out an attack against the invaders” and included links to a Facebook livestream, in which the shooting appeared, and a manifesto.
The manifesto cited "white genocide", a term typically used by racist groups to refer to immigration and the growth of minority populations, as his motivation.
The Facebook link directed users to the page of a user called brenton.tarrant.9.
A Twitter account with the handle @brentontarrant posted on Wednesday images of a rifle and other military gear decorated with names and messages connected to white nationalism. What looked like the same weapons appeared in the livestream of the mosque attack on Friday.
Facebook said it had deleted the gunman's accounts "shortly after the livestream commenced" after being alerted by police. Facebook, Twitter and YouTube all said they had taken steps to remove copies of the videos.
It was not immediately clear if the attacks at the two mosques were carried out by the same man.
Australian Prime Minister Scott Morrison said one of the men in custody was Australian.
All mosques in New Zealand had been asked to shut their doors and post armed guards, police said, adding they were not actively looking for any other "identified suspects".
Political and Islamic leaders across Asia and the Middle East condemned the killings and voiced concern over the targeting of Muslims.
"I blame these increasing terror attacks on the current Islamophobia post-9/11," Pakistani Prime Minister Imran Khan posted on social media. "1.3 billion Muslims have collectively been blamed for any act of terror."
United Nations Secretary-General Antonio Guterres reiterated "the urgency of working better together globally to counter Islamophobia and eliminate intolerance and violent extremism in all its forms," a spokesman said.
Six Indonesians had been inside one of the mosques, with three managing to escape and three unaccounted for, its foreign minister said.
Afghanistan's ambassador said three Afghans had been wounded. Two Malaysians were wounded, their foreign ministry said.
Muslims account for just over 1 percent of New Zealand's population, a 2013 census showed.
The online footage, which appeared to have been captured on a camera strapped to a gunman's head, showed him driving as music played in his vehicle. After parking, he took two guns and walked a short distance to the mosque where he opened fire.
Over the course of five minutes, he repeatedly shot worshippers, leaving more than 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.
One man, with blood still on his shirt, said in a television interview that he hid from a gunman under a bench and prayed that he would run out of bullets.
"I was just praying to God and hoping our God, please, let this guy stop," Mahmood Nazeer told TVNZ.
"The firing went on and on. One person with us had a bullet in her arm. When the firing stopped, I looked over the fence, there was one guy, changing his gun."
The video shows the gunman then driving off at high speed and firing from his car. Another video, taken by someone else, showed police apprehending a gunman on a pavement by a road.
Police said improvised explosive devices were found. The gunman's video had shown red petrol canisters in the back of his car, along with weapons.
Violent crime is rare in New Zealand and police do not usually carry guns. Before Friday, New Zealand's worst mass shooting was in 1990 when a gun-mad loner killed 13 men, women and children in a 24-hour rampage in the tiny seaside village of Aramoana. He was killed by police.