The state Assembly approved legislation Wednesday that would allow terminally ill patients to legally end their lives after an emotional and deeply personal debate, sending the proposal to the Senate that is expected to endorse it.

It was the second effort by California lawmakers this year to allow doctors to prescribe life-ending medication following the highly publicized case of 29-year-old Brittany Maynard, a California woman with brain cancer who moved to Oregon to legally take her life.

Lawmakers from both parties invoked their religious faith in arguing for and against the legislation before voting 42-33 in its favor.

“I, as a Christian, do not pretend to know what God has in mind for all of us, why there is pain or suffering in this world. But I do know he is a merciful God. And we have the ability to allow others to have a choice,” said Assemblywoman Catharine Baker, R-Pleasanton, who supported the measure. “I believe it is cruel — nothing short of cruel — to deny them that choice in their final hours and final days.”

Assembly members were seen as the stumbling block to advancing the bill; the previous version had passed the Senate. Baker, who would have represented Maynard had she stayed in California, was among several GOP lawmakers who supported the bill after previously expressing reservations.

In response to those concerns, several changes were made to boost patient protections, including requirements that the patient be physically capable of taking the medication themselves, that two doctors approve it, that the patient submit several written requests and that there be two witnesses.

The earlier measure stalled amid religious opposition and hesitant Democrats. The renewed push comes after at least two dozen states have introduced aid-in-dying legislation this year, though none of the bills has passed.

The right-to-die movement has been galvanized by the high-profile case of Maynard, who argued in widely viewed online videos that she should have been able to access life-ending drugs in her home state. Doctors are permitted to prescribe life-ending drugs in Oregon, Washington, Vermont and Montana.

It’s not clear where Gov. Jerry Brown, a lifelong Catholic and former Jesuit seminarian, stands on the issue.

Religious groups and advocates for people with disabilities have opposed aid-in-dying legislation, saying it goes against the will of God and puts terminally ill patients at risk for coerced death.

Lawmakers shared deeply personal stories of caring for terminally ill family members and of incredible recoveries. Assemblyman Mike Gipson, D-Carson, questioned the bill’s time frame, which requires a doctor to give a diagnosis of six months or less to live.

“I have seen so many miraculous turnarounds in people’s lives when the doctors have given up. The doctors have said, ‘Do funeral arrangements,’ and the prognosis has changed within a matter of hours,” said Gipson, who opposed the bill.

The measure was introduced as part of a special legislative session on health care financing convened by the Democratic governor. Brown has declined to take a position on right-to-die legislation, although his spokeswoman said earlier this year that he did not believe the session was the appropriate venue to consider it.

Several Republican lawmakers tried to block Wednesday’s Assembly vote on procedural grounds, arguing it was not the right forum for the debate.

If the effort failed in the Legislature, right-to-die advocacy group Compassion and Choices has said it would attempt to qualify for a 2016 ballot measure.

The California Medical Association earlier this year dropped its longstanding opposition to aid-in-dying legislation, taking a neutral stance.