CHRISTCHURCH, New Zealand — Abdul Aziz was praying with his four sons in the Linwood Mosque when he heard the gunshots. Rather than run from the noise, he ran toward it, grabbed the first thing he could find — a credit card machine — and flung it at the attacker.

The man dropped a shotgun, and Mr. Aziz picked it up. “I pulled the trigger, and there was nothing,” he recalled. The gunman ran to his car, where he had other weapons, and Mr. Aziz followed, throwing the shotgun at the vehicle and shattering a window.

Mr. Aziz’s actions, which he and others described in interviews, may have prompted the gunman to speed away rather than return to kill more people. Minutes later, two police officers from another town who were in the area rammed the suspect’s car into a curb and took him into custody, ending the worst mass murder in New Zealand’s modern history.

The authorities have not released a detailed account of the police response to Friday’s massacre at two mosques in the city of Christchurch, emphasizing that officers apprehended the suspect only 36 minutes after receiving the first emergency call.

But interviews with dozens of survivors, and an analysis of a video recorded by the attacker as well as one made of his arrest by a bystander, suggest that the violence ended after a near miss by the police at the first mosque — and acts of courage during and after the attack on the second.

If not for the two police officers, who have not been publicly identified, and Mr. Aziz, 48, a ponytailed furniture shop owner who fled Afghanistan a quarter-century ago, the slaughter might have continued. The suspect had two other guns in his car, the police said, as well as two homemade explosives.

“It absolutely was his intention to continue with his attack,” said Prime Minister Jacinda Ardern after the arrest of Brenton Tarrant, 28, a former personal trainer from Australia who allegedly distributed a manifesto of white extremist hatred minutes before the rampage.

The police said 42 people were killed at central Christchurch’s Al Noor Mosque and seven at the Linwood Mosque, and some attributed the lower toll at Linwood to Mr. Aziz’s decision to confront the gunman. (An additional victim died at a hospital.)