SACRAMENTO, Calif. — Gov. Jerry Brown signed legislation Monday making California the fifth state in the nation to recognize a right to die for terminally ill patients, saying the emotionally charged bill forced him to consider “what I would want in the face of my own death.”

Brown, a lifelong Catholic and former Jesuit seminarian, said he acted after discussing the issue with many people, including a Catholic bishop and two of his own doctors.

“I do not know what I would do if I were dying in prolonged and excruciating pain. I am certain, however, that it would be a comfort to be able to consider the options afforded by this bill,” the governor wrote in a signing statement that accompanied his signature.

The governor said he would not deny those comforts to others.

State lawmakers passed the bill last month. A previous version failed earlier this year despite the highly publicized case of Brittany Maynard, a 29-year-old California woman with brain cancer who moved to Oregon to end her life.

The measure was brought back as part of a special session intended to address funding shortfalls for Medi-Cal, the state’s health insurance program for the poor.

Religious groups, including the Catholic church, and advocates for people with disabilities opposed the measure, saying it legalizes premature suicide puts terminally ill patients at risk for coerced death.

The bill includes requirements that patients be physically capable of taking the medication themselves, that two doctors approve it, that the patients submit several written requests and that there be two witnesses, one of whom is not a family member.

At least two dozen states introduced right-to-die legislation this year, though the measures stalled elsewhere. Doctors in Oregon, Washington, Vermont and Montana already can prescribe life-ending drugs.