RIVERSIDE — A judge in Riverside County granted a motion Tuesday to overturn the state’s End of Life Option Act, which allows terminally ill Californians to end their life, legally, with a lethal drug.

Riverside County Superior Court Judge Daniel A. Ottolia said the legislature violated the state’s constitution by passing the right-to-die law during a special session that was limited to healthcare issues. Ottolia gave the state attorney general five days to appeal Tuesday’s ruling before it takes effect.

The attorney general’s office said shortly after the ruling that the state will appeal.

“We strongly disagree with this ruling and the State is seeking expedited review in the Court of Appeal,” Attorney General Xavier Becerra said in a released statement.

The law passed in 2016 after gaining public support based on the advocacy of UC Irvine graduate Brittany Maynard. Two years earlier Maynard, 29, who had been diagnosed with terminal brain cancer, publicized videos of her final weeks after she moved to Oregon to avail herself of the state’s Death With Dignity Act. Videos of her decision to take her own life, on Nov. 1, 2014 — and to urge passage of an assisted-death law in California — were viewed by millions.

California’s End of Life Option Act requires patients to get approval from two physicians, and mandates a 15-day waiting period between the two oral requests they must submit, one to each doctor, before they can obtain the lethal drug to end their life. Under the law, patients must be of sound mind and able to administer the drug on their own.

In July, the California Department of Public Health released a report showing that in the second half of 2016 the law was used by 191 terminally-ill Californians, who obtained lethal drug prescriptions from 173 doctors. The report said 111 people actually used the drug to end their lives.

California is one of seven states, including Colorado, Montana, Oregon, Vermont, Washington, Hawaii and the District of Columbia, to have a right-to-die law in place.

But many people and organizations continue to oppose the law on philosophical grounds, and legal challenges have come from, among others, the group of physicians who are plaintiffs in the Riverside case.

Stephen G. Larson, an attorney representing the plaintiffs, said the law should be overturned because it was improperly rushed through a special session of the legislature under “extraordinary circumstances.”

“The law had been voted down in general session numerous times over the last 20 years,” Larson said, adding that it was hurriedly passed in a session that was called to discuss other healthcare issues.

“This rush contributed to a lot of the fundamental flaws in the statute, including an amorphous definition of terminal illness, which is unworkable and subject to abuse,” he said.

An attorney for Compassion & Choices, the group that lobbies for the right-to-die law nationally, said he is hopeful Ottolia’s ruling will be overturned on appeal.

“The arguments just don’t hold water,” said Kevin Diaz, who added that he hopes the law will remain in place during the appeal process.

The lawsuit alleges among other things that the End of Life Option Act lifts liability from physicians, does not provide a proper measure for whether the patient is of sound mind when they use the lethal drugs, and that the law takes away the protections afforded to the elderly and disabled when they need it most.

But proponents say the law has given hundreds of Californians the option to end their lives with dignity.

Deborah Ziegler, Maynard’s mother, says she was disheartened by Tuesday’s decision.

“I view this law as Brittany’s legacy,” she said. “In fact, Brittany told me she was leaving me this law instead of grandchildren.”

But Ziegler added that she is confident the ruling will be appealed and that the law will be allowed to stand.

“This is not the end of the story,” she said. “It makes me sad that there are groups that want to politicize what is really a healthcare and human rights issue. The people of California are strongly behind this legislation and I don’t think they’ll stand by and allow it to be taken away from them.”

One of the lawsuit’s plaintiffs, Dr. Vincent Nguyen, a hospice and palliative care physician in Orange County, said he hopes the legal debate will result in better options for the terminally ill.

“It’s not about winning or losing,” Nguyen said. Instead, he added, it’s about “looking closely at how we can better care for people, and how we can push the healthcare system to do better.”

A devout Catholic, Nguyen said the belief in the sanctity of life transcends religion.

“It’s the law of the heart,” he said.

“I’m still passionate about this issue because I don’t want to see people die badly. We should improve care at the end of life, not just choose to help people die. “

Southern California News Group staff writer Richard De Atley contributed to this report.