WELLINGTON, New Zealand—A suspected Islamist extremist’s knife attack has prompted New Zealand authorities to accelerate an overhaul of counterterrorism laws, including by criminalizing the planning of an attack for the first time.

The stabbing of supermarket shoppers on Friday was the first act of terrorism in New Zealand since a white supremacist murdered 51 people at two mosques in the southern city of Christchurch in March 2019. Five of the stabbing victims are hospitalized, three in critical condition. The attacker, a Sri Lankan man who authorities said was inspired by Islamic State, was shot and killed by police.

The attacker, who was about 32 years old, hasn’t been named. The government said he had been released from custody in mid-July with a year-long probationary-type sentence after three years awaiting trials on charges that included possessing extremist material and having an offensive weapon—a hunting knife. He was under round-the-clock surveillance by a team of 30 police.

Prime Minister Jacinda Ardern said an updated counterterrorism law, introduced in April but under discussion since 2018, will be voted on by Parliament before the end of September. The main opposition party said it supports urgent passage. But some legal experts and Islamic groups have cautioned against fast-tracking.

“We don’t believe any such legislation should be rushed on the basis of this attack,” said Anjum Rahman, a spokeswoman for the Islamic Women’s Council New Zealand. “The bill requires proper scrutiny.” She said the government hasn’t made the case that specific provisions in the law could have prevented the attack.

Andrew Geddis, a law professor at the University of Otago, said urgent fixes are no substitute for good lawmaking, and that part of the impetus for the rush is a political desire to insulate the government from criticism.

“But I do recognize why both the government and security services will think differently, as ultimately they carry the responsibility if another attack takes place,” he said.

A police officer leading employees of a nearby store away from the scene of Friday’s knife attack in a New Zealand supermarket.

Photo: stuff limited/ricky wilson/Reuters

Several countries including New Zealand strengthened or introduced terrorism laws following the Sept. 11, 2001 al Qaeda attacks on the U.S. Preparing a terrorist attack has been a criminal offense in Australia since 2002. The U.K. criminalized preparation and assisting preparation in 2006.

Ms. Ardern’s response to the supermarket attacks is a political balancing act—promising quick action to plug a legal loophole while seeking to keep blame for the attack from falling on her government. She said authorities had exhausted options for keeping the attacker in prison, and that even if the new law had been in place it might not have prevented the attack.

“I do not think it is fair to make an assumption that that law change in itself would have made the difference in this case. We don’t know that to be true,” Ms. Ardern said. “This was a highly motivated individual who used a supermarket visit as a shield for an attack.”

Underscoring the risk they believed the extremist posed, police in late August urged officials to consider expedited passage of the counterterrorism law to give them more legal options. Forty-eight hours later—the day of the attack—New Zealand’s justice minister asked for haste from the head of the parliamentary committee overseeing the legislation.

The introduction of the draft law in Parliament in April began a lengthy process of submissions, committee hearings and three parliamentary debates. At the time of the attack, it had been through its first debate.

The attacker moved to New Zealand in 2011 on a student visa. Five years later, he received police warnings for promoting violent extremism on social media. He was briefly imprisoned in May 2017 after allegedly attempting to travel to Syria. In August 2018, while on bail, he was arrested after buying a hunting knife and being found to have extremist publications.

Police Commissioner Andrew Coster said the attacker was shot within about 60 seconds of the supermarket commotion coming to the attention of plainclothes officers shadowing the attacker. Based on CCTV footage, the first stabbing had occurred about 60 to 90 seconds earlier.

The man had spent 10 minutes appearing to shop, which was how he obtained the knife, Mr. Coster said. Police may never be able to ascertain if the attack was opportunistic or planned, he added.

Write to Stephen Wright at stephen.wright@wsj.com