For a while, it seemed like this could be the year Maryland lawmakers would make it legal for doctors to prescribe a lethal dose of medication to terminally ill patients who want to end their lives.

Aid-in-dying legislation, which stalled in committee for the past four years, passed the House of Delegates last month, despite strong opposition from the Catholic Church and emotional misgivings from dozens of lawmakers. It was approved by the Senate Judicial Proceedings Committee last week — albeit with numerous amendments that advocates said would have made it the strictest such law in the country.

But the bill failed in dramatic fashion Wednesday when the full Senate deadlocked 23 to 23 on whether to advance it. Sen. Obie Patterson (D-Prince George’s) did not vote, saying he “could not bring myself to move right or left on the bill” after a 50-minute debate that largely focused on personal choice and the sanctity of life.

Sen. Pamela G. Beidle (D-Anne Arundel) initially voted in favor of the measure, which would have meant a 24 to 22 vote. She switched her vote to “No” just before the tally was taken.

Eight other states allow doctors to help patients end their lives, and New Jersey’s legislature approved an aid-in-dying bill this week.

Sen. William C. Smith Jr. (D-Montgomery), the lead sponsor of the Maryland bill, said the tie vote marked significant progress, even though the legislation would not become law this year.

“Never before has this bill come out of the House and never before has it come out of the Senate committee, and we had 23 senators go along with it,” Smith said. “It definitely marks a lot of progress, and I can be proud of that.”

Public attitudes have shifted regarding what advocates call “death with dignity,” sometimes referred to as medically assisted suicide. More than 6 in 10 Maryland residents said they were in favor of the legislation, according to a recent Goucher College poll.

“Maryland is ready for it,” Smith said. “Obviously the Senate is not quite ready.”

Advocates said they plan to continue to push for the bill in the future. “There are terminally ill residents in Maryland who are waiting for this option,” said Kim Callinan, chief executive of Compassion & Choices, which has led efforts across the country to pass aid-in-dying legislation. “It’s our intention to push forward. . . . It’s just going to take more time.”

Wednesday’s vote, and the emotional debates over the bill in both chambers of the legislature, demonstrated the strong role religion continues to play in public policy. Many Catholic and African American lawmakers voted against the bill, reflecting a general suspicion of end-of-life options that is stronger among those demographics than in more secular or mostly white communities. The Catholic Church opposes suicide and says human beings should not help others take their own lives.

Patterson, who is African American and attends a Baptist church in Fort Washington, said his faith played a role in his decision not to vote. He declined to elaborate.

Nine Democrats voted against the bill, including Senate President Thomas V. Mike Miller Jr. (D-Calvert), a devout Catholic who is battling Stage 4 prostate cancer. Only one Republican, Sen. Chris West (R-Baltimore County), supported the measure.

“I think the Catholic Church definitely played a strong role,” said Smith, who is African American and a Catholic. “For some members, that was the defining aspect of their decision-making,”

The initial version of the Maryland legislation was modeled after an Oregon law that applies to terminally ill patients whose doctors say they have six months or less to live. Patients would have to make three requests to end their lives, both oral and in writing, with waiting periods and other precautions. Similar statutes have been enacted in the District, California, Colorado, Hawaii, Montana, Oregon, Vermont and Washington state.

The bill was approved 74 to 66 in the House of Delegates, after a prolonged discussion in which lawmakers gave accounts of the deaths of their loved ones and shared details of their own challenging health diagnoses and their faith.

But the legislation was heavily amended in the Senate Judicial Proceedings Committee, with changes that would allow doctors to be sued for helping patients die; require a mandatory mental-health referral from a psychiatrist, psychologist or licensed clinical social worker; mandate that patients have an attending doctor and a consulting doctor from different practices; and require that the consulting physician provide patients with a written list of alternative treatments.

Advocates said the changes imposed so many roadblocks that few, if any, doctors or patients would likely opt to take advantage of the bill even if it became law.

“I couldn’t ask a doctor in good conscience to practice under this law,” Callinan said earlier this week. She described the amended bill as a “setup” for lawsuits against doctors.

Del. Shane Pendergrass (D-Howard), who sponsored the bill in the House for four years, said the amended bill would have offered false hope to dying patients, and she would not have been able to support it.

During debate on the Senate floor Wednesday, Sen. Bryan W. Simonaire (R-Anne Arundel) spoke about his father’s recovery from cancer, and said he did not believe the state should allow even terminal patients to get help to end their lives.

“There are no do-overs in this type of law,” Simonaire said. “Once the life is taken, it is final.”

Sen. Delores G. Kelley (D-Baltimore County), whose daughter died of cancer, said no one should be able to decide for another person what level of suffering God wants them to endure. “What happens with my life, I should have some autonomy,” she said.

In the District, at least two terminally ill patients have legally ended their lives since the city’s aid-in-dying law took effect in 2017 over opposition from some Republicans in Congress. Regulators plan to issue a report in mid-April with more statistics about the D.C. law and its use.

A spokesman for D.C. Council member Mary M. Cheh (D-Ward 3), who authored the District legislation, says the office periodically gets calls from Maryland residents asking if they can go through the process in the District. But the law requires residency in the city.

Fenit Nirappil contributed to this report.