Drug giant GlaxoSmithKline agreed to cough up a record $3 billion penalty to settle sweeping US criminal and civil probes for illegally peddling many of its most popular meds for more than a decade.

The seven-year investigation by the Justice Department and other federal agencies involved some of the worst allegations the drug industry has seen in years, affecting an entire generation, officials said.

The charges included bribing doctors, cooking safety data, rigging prices and pushing potent drugs on teens for risky and unapproved uses. Some of the misuses turned life-threatening, according to officials.

“This historic settlement is a major milestone in our efforts to stamp out health-care fraud,” said Bill Corr of Health and Human Services.

The feds said the company, in one key scheme, lavished doctors with luxury spa junkets, gifts and millions in speaking fees in a conspiracy to boost prescriptions for the antidepressant pill Wellbutrin. The firm fraudulently claimed it also worked for weight-loss, curbing substance abuse and treating sexual dysfunction.

Glaxo’s sales force even hawked the pricey drug to doctors as the “happy, horny, skinny pill,” concealing that it was never approved for any of those uses and likely was dangerous.

Another antidepressant, Paxil, was fraudulently marketed to increase sales to children and teens, without disclosing it could trigger suicidal behavior.

A total of nine drugs were targeted in the crackdown, including Wellbutrin, Paxil, Advair, Lamictal, Zofran, Imitrex, Lotronex, Flovent, Valtrex and Avandia.

The $3 billion in settlement proceeds — $2 billion to end a handful of criminal charges and $1 billion to end civil charges — will be spread among federal agencies, with states sharing about $478 million of the penalties.

Glaxo CEO Andrew Witty called the deal “a resolution to difficult, long-standing matters” dating back to 2004. Shares in the US rose 79 cents to close at $46.36.