When the executives who distribute 5-Hour Energy, the popular caffeinated drinks, learned that attorneys general in more than 30 states were investigating allegations of deceptive advertising — a serious financial threat to the company — they moved quickly to shut the investigations down, one state at a time.

But success did not come in court or at a negotiating table.

Instead, it came at the opulent Loews Santa Monica Beach Hotel in California, with its panoramic ocean views, where more than a dozen state attorneys general had gathered last year for cocktails, dinners and fund-raisers organized by the Democratic Attorneys General Association. A lawyer for 5-Hour Energy roamed the event, setting her sights on Attorney General Chris Koster of Missouri, whose office was one of those investigating the company.

“My client just received notification that Missouri is on this,” the lawyer, Lori Kalani, told him.

Ms. Kalani’s firm, Dickstein Shapiro, had courted the attorney general at dinners and conferences and with thousands of dollars in campaign contributions. Mr. Koster told Ms. Kalani that he was unaware of the investigation, and he reached for his phone and called his office. By the end of the weekend, he had ordered his staff to pull out of the inquiry, a clear victory for 5-Hour Energy.

The quick reversal, confirmed by Mr. Koster and Ms. Kalani, was part of a pattern of successful lobbying of Mr. Koster by the law firm on behalf of clients like Pfizer and AT&T — and evidence of a largely hidden dynamic at work in state attorneys general offices across the country.