LOS ANGELES — A state judge overturned California's doctor-assisted suicide law on Tuesday, saying the legislation opening the door to life-ending drugs for the terminally ill was unconstitutional because it was introduced in the wrong forum.

Judge Daniel A. Ottolia of State Superior Court in Riverside said the law did not fall within the scope of health care services when the bill creating it was debated during a special section on the topic. He did not rule on the legality of allowing Californians to kill themselves.

He stayed his order for five days. California's attorney general, Xavier Becerra, said he would appeal immediately.

"We strongly disagree with this ruling and the state is seeking expedited review in the Court of Appeal," Becerra said in a statement.

The Life Legal Defense Foundation, American Academy of Medical Ethics and several physicians challenged the law, which allows adults to obtain a prescription for life-ending drugs if a doctor has determined that they have six months or less to live. The plaintiffs say the law lacks safeguards to protect against abuse.

State Sen. Bill Monning, who co-authored the legislation, said he was disappointed by the ruling, but confident that it would be overturned. "The court order, if allowed to stand, would invalidate people's rights," he said.

"Gov. Jerry Brown signed the law, it passed both houses, it went through hearings," Monning said. "There were no shortcuts."

Monning said a report to the Legislature covering the second half of 2016, the first full year the law was in effect, concluded that 111 Californians had taken advantage of the opportunity to end their lives.

George Eighmey, national board president of the nonprofit Death With Dignity, said California is one of seven states that have, along with the District of Columbia, passed similar laws allowing terminally ill patients to receive drugs to end their lives.

Even if a rapid appeal is successful, Eighmey said he fears that dying people who want to commit suicide will be left in limbo. "There might be people in the process of getting medication being placed on hold," Eighmey said. "And dying people can’t be placed on hold."

The Life Legal Defense Foundation, whose attorneys argued in court Tuesday against the End of Life Option Act, expressed elation.

“We are thrilled by today’s ruling, which reinstates critical legal protections for vulnerable patients,” executive director Alexandra Snyder said in a statement. “The court made it very clear that assisted suicide has nothing to do with increasing access to health care and that hijacking the special session to advance an unrelated agenda is impermissible.”