Members of the Bangladesh cricket team had just arrived by bus at Masjid Al Noor mosque for Friday afternoon prayers when they heard gunshots.

Had they arrived a few minutes earlier they would have been inside the mosque, where at least 30 people were killed by a gunman with an automatic rifle. Another nearby mosque in Christchurch was also attacked, and overall 49 people were killed and more than 20 seriously injured.

Police charged one person, detained three others, and defused explosive devices in what appeared to be a carefully planned and racist attack.

When the bus carrying some players and coaching staff arrived at the mosque, they heard but did not see the shootings, Mohammad Isam, a journalist travelling with the Bangladesh team, told The Associated Press.

The players were kept on the bus by police, then later allowed to leave and to walk to nearby Hagley Oval, where they'd been scheduled to begin the third cricket test against New Zealand on Saturday.

The players eventually returned to their hotel shaken, distressed, and in no mental state to consider playing cricket, Isam said.

The test match was cancelled, and the Bangladesh squad was preparing to fly home on Saturday.

Team manager Khaled Mashud told espncricinfo.com the players had a lucky escape.

"We must have been about 50 yards from the mosque. I would say we were really lucky," Mashud said. "Had we reached even three or four minutes earlier, we probably would have been inside the mosque."

Players and team staff had earlier taken to social media to recount their narrow escape.

Opening batsman Tamim Iqbal tweeted: "entire team got saved from active shooters. Frightening experience and please keep us in your prayers."

Performance analyst Shrinivas Chandrasekaran posted: "Just escaped active shooters. Heartbeats pumping badly and panic everywhere."

Mushfiqur Rahim posted "Alhamdulillah Allah save us today while shooting in Christchurch in the mosque ... we r extremely lucky ... never want to see this things happen again ... pray for us"

Bangladesh Cricket Board President Nazmul Hassan Papon said nobody expected such an event to occur in New Zealand, but the shootings highlighted the fact that teams from South Asia deserved the same high level of security when they travelled as their home countries provided to visiting teams.

"It is not only, say, Bangladesh or India or Pakistan at the high risk," he said. "That is why we feel that the security that countries like Bangladesh gives to other teams when they come to play in Bangladesh, we should also get the similar type of security arrangement or support from the host country."

Former Bangladesh international cricketer Sajol Ahmed Chowdhury gave thanks that all the players were safe.

"The Bangladesh cricket team is our national asset," he said. "There is a World Cup coming (in May in England) which is a big concern. We hope that this sort of incident never happens again."

New Zealand Cricket chief executive David White said the cricket community was "shocked and appalled."

"On behalf of New Zealand Cricket heartfelt condolences to those affected," chief executive David White said. "I've spoken to my counterpart at Bangladesh cricket -- we agree it's inappropriate to play cricket at this time. Both teams are deeply affected."

International Cricket Council chief executive David Richardson said it "fully supports the decision to cancel the test match."

"Our thoughts and sincere condolences go out to the families and friends of those affected by this horrendous incident in Christchurch," Richardson said.

The test match in Christchurch was the first to be cancelled since 2002, when a match between Pakistan and New Zealand in Karachi was called off after a terrorist bombing in the city.

Map of mosque attacks in News Zealand (Â鶹´«Ã½)