WASHINGTON — Juul Labs, the nation’s largest electronic-cigarette company, donated tens of thousands of dollars to the campaigns of state attorneys general in an effort to build relationships with these powerful officials and potentially head off legal challenges over how it promoted and sold its vaping products.

But the company’s approach hasn’t stopped officials from taking action. Thirty-nine states announced late last month that they will investigate whether Juul’s early viral marketing efforts illegally targeted teens and made misleading claims about the nicotine levels in its devices.

Health officials have declared underage vaping an epidemic, largely driven by the discrete, high-nicotine, fruity-flavored pods that Juul sold until late last year.

“Juul really created this crisis,” said Dr. Scott Gottlieb, the former Food and Drug Administration commissioner. “Juul created the pool of nicotine-addicted teens and I think they popularized the idea of vaping among kids.”

The Food & Drug Administration and Congress are probing whether Juul’s early promotions deliberately appealed to minors, including the use of online influencers, “launch parties” and product giveaways.

Yet Juul may face an even bigger threat from the nation’s state attorneys general, who previously used their collective power to force changes in the way Big Tobacco companies do business.

In an emailed response to written questions, a Juul spokesman declined to say how many state attorneys general company representatives have met with. Juul, the spokesman said, is working to earn “the trust of society,” by working with various government officials. The company says its outreach to attorneys general was aimed at collaborating with them on key issues, including combating underage use.

Documents obtained by The Associated Press through open records requests shed new light on the unusual connection Juul forged with Iowa’s Tom Miller, the longest serving state attorney general in U.S. history. The records show that Miller served as a behind-the-scenes adviser, helping the company respond to media requests and inquiries from government officials. Miller did not receive campaign contributions from Juul.

The documents also provide new details about former state attorneys general who were hired by the company, including Massachusetts’ Martha Coakley, who became a key messenger as Juul made the case that it was working to keep its products away from minors while simultaneously pitching its technology as an anti-smoking tool for adults.

Juul’s outreach included thousands of dollars in campaign contributions to individual state attorneys general, five of whom later met with the company’s representatives, according to the records. The company also donated $50,000 each to the Republican and Democratic fundraising committees that support the election of attorneys general candidates.

Those donations won Juul corporate membership in both groups, a status that came with invitations to semiannual retreats and conferences attended by attorneys general and their staff. These events provide opportunities for companies to lobby state officials.

Under intense legal and political pressure, San Francisco-based Juul has made a number of concessions in recent months, including halting all U.S. advertising and pulling all of its flavors except menthol and tobacco.

Former state law enforcement officials say meeting with business executives is not unusual. But even basic information about these meetings typically isn’t publicly available.

So far, nine attorneys general have filed lawsuits against Juul, with Massachusetts’ chief legal officer, Maura Healey, the latest to sue the company. Her lawsuit alleges that Juul bought advertisements on websites designed for children, including seventeen.com and cartoonnetwork.com.

Before Juul began donating money to campaign coffers, the company forged an unlikely partnership with Miller, the Iowa attorney general with 37 years in office. A Democrat, Miller frequently cites his work on the landmark 1998 settlement with the tobacco industry. His office hasn’t joined the multistate investigation of Juul.

Emails obtained by the AP show that Juul sought Miller’s counsel on how to respond to inquiries from government officials and media outlets. And even as more teens were vaping, Miller urged the public not to “overreact.” Portions of Juul’s interactions with Miller were previously reported by Politico and Vice News.

Former state law officials say there is little precedent for such a close partnership between an attorney general and a private company.

Miller told the AP he became involved with Juul to try to help stop underage use of the company’s products.

By spring 2018, Juul and Miller were in regular contact, emails show. In April his office issued a press release titled, “Juul offers opportunity to reduce smoking rates,” highlighting the company’s potential to shift smokers away from cigarettes.

In subsequent months, Juul would seek Miller’s guidance or encourage him to conduct interviews with journalists from The New York Times, NBC and CBS, amid nationwide reports of teens becoming addicted to Juul.

In April 2019, Miller penned a positive profile of Juul co-founders James Monsees and Adam Bowen for Time magazine’s annual list of the 100 most influential people.

Miller rejected any suggestions that Juul benefited from its association with him. He stressed that his involvement with the company centered on vaping’s potential to reduce smoking.

“It wasn’t to speak well of Juul,” Miller told the AP in an interview.

In late October 2018, Juul’s political action committee donated more than $38,000 to incumbent state attorneys general and one first-time candidate for the office, according to campaign finance records. Documents obtained from state officials show Juul representatives later secured meetings with several attorneys general or their senior staff.

The meetings gave Juul an opportunity to promote its vaping products over traditional paper cigarettes, using customized slide presentations detailing the health toll of states’ smoking rates.

When Juul met with Georgia Attorney General Chris Carr and his staff in May 2019, the company’s team included a new hire: Martha Coakley, the former attorney general of Massachusetts. Coakley, a Democrat, had joined the company a month earlier, giving Juul another messenger with a state attorney general’s credentials.

“We look forward to staying in touch,” Coakley told Carr’s chief of staff in a post-meeting email.

Katie Byrd, Carr’s spokeswoman, said a $3,000 contribution made by Juul’s political action committee to Carr’s 2018 re-election campaign wasn’t a factor in his decision to accept the meeting.

But the one-on-one time didn’t prevent additional scrutiny.

Last month, Carr announced he was joining 38 other attorneys general investigating Juul.

“Our office is committed to learning all the facts so that we can best protect Georgia’s youth from products that could be harmful to them,” Carr said in a statement.