Members of the Bangladesh cricket team narrowly missed the New Zealand mosque attack.

The players had just arrived by bus at the Masjid Al Noor mosque for Friday afternoon prayers when they heard gunshots.

If they had 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 dozens seriously injured.

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

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

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

The test match was cancelled and the Bangladesh squad is 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. Had we reached even three or four minutes earlier, we probably would have been inside the mosque.”

Players and staff took 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 said: “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 in New Zealand, but the shootings highlighted the fact that teams from south Asia deserve the same level of security when they travel as their home countries provide 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 Sajol Ahmed Chowdhury gave thanks that all the players were safe.

“The Bangladesh cricket team is our national asset. 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,” Mr 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,” he added.

The Test 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.