Shoppers and staff at a New Zealand supermarket have been praised for their bravery after authorities said they managed to stop a man from hurting others after he stabbed four people in an attack, critically wounding three of them.

New Zealand Police superintendent Paul Basham said he had watched CCTV footage of the attack at a Countdown supermarket in the city of Dunedin and that the actions of the bystanders in detaining the man until police arrived was “nothing short of heroic”.

“What I can say is that those that intervened, some of whom became injured themselves, I think have acted selflessly and with great courage to prevent this man from hurting anybody else,” he said.

Two of those wounded were supermarket staff members.

On Tuesday, authorities said three of the injured had improved to a serious but stable condition, while the fourth person was in a moderate condition.

Police said they had charged a 42-year-old man with four counts of attempted murder. The man is due to make his first court appearance later. The suspect was also injured in the attack and was initially treated for his wounds under police guard before being transferred to jail.

People in the store at the time told local media that it was a chaotic scene as some people began screaming and running towards the exits while others rushed to help.

Prime Minister Jacinda Ardern said the motivation for the attack had not been established but police did not have any evidence to suggest it was domestic terrorism.

“Needless to say that such an attack is hugely concerning, and I do want to acknowledge the really early reports of courageous acts by bystanders who have taken action in order to protect those around them,” Ms Ardern said. “Our thoughts are with all those affected by this attack.”.

Health authorities said three of the wounded had been admitted to the intensive care unit at Dunedin Hospital.

“We are shocked and devastated by the events in our Dunedin Central Store this afternoon,” Countdown said in a statement.

“Our priority right now is our injured team members and caring for our wider team in the wake of this extremely traumatic event. We are deeply upset that customers who tried to help our team members were also injured.”

Dunedin is home to about 130,000 people.