Johnson & Johnson must pay $572 million to Oklahoma for wrongfully marketing opioid drugs, a judge ruled in the first trial by a state seeking compensation for the public-health crisis spawned by the painkillers.

Shares rose 4 percent as investors welcomed the ruling. Oklahoma had sought as much as $17.5 billion.

Oklahoma Judge Thad Balkman ruled Monday that J&J created a temporary public nuisance by duping doctors into overprescribing its opioid-based medications and must cover the government’s costs in dealing a surge in rates of addiction and overdoses. The award provides funds to beef up emergency services and treatment budgets.

Representatives for J&J didn’t immediately respond to requests for comment on the ruling.