TRENTON, N.J. - New Jersey Gov. Phil Murphy said Monday he will sign legislation allowing terminally ill patients to seek life-ending medication.

New Jersey will join six other states and the District of Columbia that have similar laws once the bill is signed.

“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, a Democrat, said in a statement after the Democrat-led Assembly and Senate passed the measure in close votes.

Lawmakers have tried unsuccessfully since at least 2012 to advance the legislation. The bill got some attention in New Jersey in 2014 around the time that 29-year-old Brittany Maynard, who was terminally ill with brain cancer, was in the national spotlight.

Maynard drew news coverage after publicizing that she and her husband, Dan Diaz, moved to Portland, Oregon, from Northern California so she could use the Oregon law to end her life on her own terms.

Under the bill, adult New Jersey residents with a prognosis of six months or less to live could request the life-ending medication.

The legislation includes several measures that legislators called “safeguards.” They include requiring patients to make two requests, along with a chance to rescind the request.

Supporters say the new law would let qualified patients decide to end their own lives in a dignified manner.

“There is no good reason for them to be forced to prolong their pain and suffering or to prolong the grief of their loved ones if they make that choice,” Democratic state Sen. Nicholas Scutari said in a statement.

Opponents argue the bill will hurt the most vulnerable in society and that the state should instead work to improve its health care system.

“New Jersey ought to be investing in better care and support at the end of life, not enshrining this dangerous public policy into law,” Matt Valliere, executive director of Patients Rights Action Fund, said in a statement.

Murphy didn’t specify when he will sign the bill. The measure passed the Assembly 41-33, with 4 abstentions. It cleared the Senate 21-16.

California, Colorado, Hawaii, Oregon, Vermont, Washington and D.C. all have similar legislation.