WELLINGTON, New Zealand -- New Zealand lawmakers on Wednesday voted in favour of a bill to legalize euthanasia, a watershed moment that ended a contentious two-year debate.

But the final decision will rest with voters, who will need to approve the bill in a referendum next year for it to go into effect. Polls have indicated a majority support the measure.

The bill passed 69-51. People in the public gallery cheered and clapped when the results were read out.

The bill applies only to people who are terminally ill and likely to die within six months. To be eligible, a person must be in irreversible physical decline and experience "unbearable suffering" that cannot be relieved in any other way they find tolerable.

But the bill goes further than measures in many other jurisdictions around the world by allowing a patient to not only take a lethal dose of prescribed drugs themselves, a method known as medically assisted suicide, but also allowing a doctor or nurse to administer the drugs.

The bill attracted a record 39,000 public submissions, most of them opposing the measure.

Politicians from mainstream parties had tried unsuccessfully to move forward euthanasia legislation in the past, but this time the bill was sponsored by David Seymour, the Parliament's lone representative from the libertarian ACT Party.

"It makes me proud of our country that we can have this debate, and we can actually get progress, and become a more free and compassionate society," Seymour said. "I think that is fantastic."

Lawmaker Maggie Barry, who opposed the bill, said it amounted to bringing back state-sanctioned killing, something the country had abandoned more than 50 years ago when it abolished the death penalty. She said Seymour and the other supporters couldn't prove there wouldn't be unintended consequences.

Seymour said the bill's passage marked the start of a campaign to get the referendum passed.

"If you look at all of the public opinion polling, there's overwhelming support, and it should easily pass," he said.

The referendum will take place at the same time as another referendum to legalize recreational marijuana and the general election. A final date hasn't been set although it can be no later than next November.

Among those countries to have legalized euthanasia or medically assisted suicide are Belgium, Canada, Colombia, Luxembourg, the Netherlands, and Switzerland. Eight U.S. states and Washington D.C. have also legalized medically assisted suicide. In addition, Montana doesn't have a specific law on the books but a state Supreme Court ruling has allowed such deaths to proceed.