SACRAMENTO, Calif. (Reuters) - The California legislature on Friday approved a bill to legalize physician-assisted suicide for terminally ill patients despite opposition from religious and disability rights groups, sending it to Democratic Governor Jerry Brown for his approval or veto.

The bill would allow mentally competent patients to request a prescription that would end their lives if two doctors agree the patients have only six months to live.

The measure, based on a similar law in Oregon, passed the state Senate on Friday on a vote of 23-14, after passing the Assembly on Wednesday.

"We are here today on the precipice of granting a wish that I was not able to give my mother," said Senator Hannah-Beth Jackson, who said her mother died in agony from a form of leukemia.

It was the subject of weeks of debate, as supporters argued that the measure would allow people in the last stages of terminal illness to die peacefully, while advocates for seniors and the disabled argued it could make people vulnerable to greedy relatives or others who wished to avoid taking care of them or inherit their money.

Some religious organizations, including the Roman Catholic Church, also opposed the bill.

The measure allows physicians to prescribe medication to end a person's life if two doctors agree the person has only six months to live. The person also must be deemed mentally competent by a mental health professional.

Tricking or coercing patients to end their lives would be a felony under the measure.

Physician-assisted suicide, which is legal in Washington state, Montana and Vermont, gained new impetus in the most populous U.S. state last year after a 29-year-old brain cancer patient, Brittany Maynard, moved from California to Oregon to take advantage of that state's Death with Dignity Act.

A measure introduced after Maynard's death won the support of the state Senate in June but died in the Assembly's Health Committee. It was re-introduced last month as part of a special session on healthcare, during which the Assembly Health Committee was comprised of members more sympathetic to the bill.

The California Medical Association, which for years has opposed assisted suicide, withdrew its opposition last May and took a neutral stance instead. Many doctors continue to oppose it, saying they should preserve life rather than help end it.

Brown, a former Catholic seminarian, has not said whether he will sign it.

(Editing by Sandra Maler and Bill Trott)