Minnesota lawmakers reached an 11th-hour deal Monday that could generate more than $20 million a year in fees from prescription drugmakers to combat the opioid epidemic.

Supporters say the agreement, announced hours before the Legislature's adjournment deadline at midnight Monday, could make Minnesota the first state in the nation to establish a separate state fund dedicated to opioid addiction prevention and treatment.

"This is a day I'm really proud to be a legislator," said Rep. Dave Baker, a Willmar Republican whose 25-year-old son Dan died of an overdose in 2011. "This is going to save a lot of lives."

Lawmakers in both chambers approved the compromise language Monday night, the House 109-25 and the Senate 60-3. It now heads to the desk of Gov. Tim Walz, who is expected to sign it.

Versions of the proposal passed both chambers with bipartisan support earlier this session. But the legislation hit a snag in recent weeks amid a disagreement over whether to lower or roll back some licensing fees if the state wins a legal settlement in one of several pending lawsuits against the companies that make prescription drugs.

After a week of intense negotiations, lawmakers brokered a compromise to lower the fees on some companies in five years if the fund reaches $250 million, either through a large settlement or from the fee collections. At that point, the amount paid by the largest opiate manufacturers would drop from $305,000 to a little more than $5,000 a year. Supporters say even then, roughly $12 million would be generated each year.

Democrats initially resisted linking the fees to possible settlements in the pending lawsuits.

"This bill is not about retribution, it's about taking care of the needs of Minnesotans and making sure we don't have any more lost people, lost loved ones," said Republican Sen. Julie Rosen, chief author of the Senate bill and a key figure in the negotiations. "This is one thing we could have done, and we got it done."

The deal also resolves disagreements over how to spend the money. More than a third of the revenue — between $7.7 million and $8.5 million a year — will go to grants distributed by a new 19-member council tasked with crafting a comprehensive state response to the epidemic. It also provides funding for overdose prevention, efforts aimed at stopping illegal drug trafficking and child protective services programs. Another $2 million will go to traditional healing programs aimed at providing nonnarcotic alternatives for pain management in tribal nations and indigenous communities, a priority for the Walz administration.

In addition to the funding, the bill sets stricter limits on opiate prescriptions for acute pain and sets continuing education requirements for medical providers who prescribe addictive drugs. Doctors could override the caps if they feel it's medically necessary.

"This is a really comprehensive bill," said DFL Rep. Liz Olson, chief sponsor of the House bill. "It is not just about tackling the crisis in a one-dimensional way. It is about ongoing, dedicated revenue to tackle this crisis in a multipronged approach."

Similar proposals, including so-called "penny-a-pill" legislation, stalled in previous years under intense lobbying from drug manufacturers. A spokesman for a leading industry trade group did not respond to a request for comment Monday.

But this year, advocates say a shared commitment to getting an agreement, along with a growing awareness of the scope of the crisis, changed the dynamic and paved the way for bipartisan compromise.

"I think the Legislature has recognized this is an ongoing, long-term severe crisis that's not abating, and there's a recognition that Big Pharma caused the problem," said Michael Daub, a board member with the Steve Rummler Hope Network. "They triggered this."

Lawmakers on both sides of the aisle emphasized that the compromise bill is just a first step toward addressing the opioid epidemic and that more action may be needed. Sen. Chris Eaton, DFL-Brooklyn Center, said she was disappointed that funding related to overdose-reversal drugs like naloxone was cut in the final version. Access to that drug, she said, could have saved her own daughter Ariel from an overdose death 12 years ago. Still, Eaton said she was gratified to see a version of the bill pass that she and Baker have pushed for years.

"This road both of us got on when we lost our children to the opioid epidemic has been a rough one," Eaton said. "We've worked hard, and I think we have a good product here. I'm hoping it makes a difference and saves lives."