New Jersey is poised to become the eighth state to allow terminally ill patients to legally end their lives after a vote Monday that for years had eluded supporters of the so-called right-to-die movement.

With the Legislature narrowly approving the Medical Aid in Dying for the Terminally Ill Act, the bill now goes to Gov. Phil Murphy, a Democrat, who pledged his support.

“Allowing terminally ill and dying residents the dignity to make end-of-life decisions according to their own consciences is the right thing to do. I look forward to signing this legislation into law," Murphy said in a statement.

The bill's approval is in itself a key victory for supporters and for Democrats in the Legislature who have tried for years to get it passed. The Assembly had passed it twice, in 2014 and 2016, only to see it stall in the Senate.

Just before the deciding vote, Sen. Nicholas Scutari said it was "perhaps one of the most consequential bills that we'll act on in our time here."

The bill passed each chamber with the minimum number of votes: 21 in the Senate and 41 in the Assembly.

Weed vote canceled:NJ legal weed vote didn't happen today. So now what?

Viral play:NJ students performed 'Alien' and it went viral on social media

If it becomes law, terminally ill patients who are mentally competent adults would be able to request and then use a prescription for lethal medication.

Two physicians would be required to attest that the person had less than six months to live. The patient would have to ask for the medication three times — twice orally and once in writing — before receiving it. The written request would have to be witnessed by two people, including one who is not a family member, a beneficiary of the patient's will or the attending physician.

The patient would then be required to self-administer the medicine, if he or she decides to take it at all.

The aid-in-dying bill was one of two major measures scheduled for Monday that posed a test of lawmakers' consciences. A vote on legalizing recreational marijuana was canceled because of a lack of support in the Senate.

Proponents of assisted suicide have been pressing for the change, saying terminally ill people should have the right to end their lives without prolonged suffering. But critics have said such a law could lead to a more permissive policy that opens up assisted suicide to other categories of people.

Sen. Robert Singer, R-Ocean, wondered aloud on the Senate floor if the state would put too much trust in doctors. He noted that in response to the opioid epidemic the state has put limits on how much doctors can prescribe. But the bill would put a person's fate in the hands of physicians.

"What if they're wrong? What if they made a mistake and that person is not going to die?" Singer said.

Others view the measure as an indicator of a more sympathetic society. Sen. Richard Codey, D-Essex, said "it's about you deciding for yourself what you want to do with the end of your life."

A longtime advocate for the bill, Susan Boyce, 55, of Rumson, was visibly emotional following the vote in the Senate. Boyce, who has a rare genetic disorder called alpha-1 antitrypsin deficiency that has caused a decrease in her lung function, said she would like to have the option of medically assisted suicide “because people with my disease can have a very slow, breathless end of life.”

“I think that it’s going to give a lot of people peace of mind, a lot of people who know that at some point down the road that this could come up for them,” she said. “And just knowing that it’s an option is huge. It’s just a huge relief.”

Staff Writer Nicholas Pugliese contributed to this article.