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 Gov. Jerry Brown for his approval or veto.

The bill will allow mentally competent patients to request a prescription that will end their lives if two doctors agree the patients have only six months more 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.