In September 1983, Robert F. Kennedy Jr. fell ill on a flight to Rapid City, S.D. The pilot radioed ahead for medics. By dint of his famous name, Mr. Kennedy, then 29 and fresh out of law school, was taken to a V.I.P. room at the airport, where investigators found heroin in his luggage.

By his own account, Mr. Kennedy, who later pleaded guilty to a felony charge of possessing heroin, had become addicted to the drug in his teens, as he struggled to cope with the assassination of his father. Two days after the airplane episode, he checked himself into a New Jersey drug treatment center. He says he has been sober ever since.

Now Mr. Kennedy is President-elect Donald J. Trump’s pick to be health secretary, a nomination he landed after a renegade presidential campaign in which he cast his life as a redemption story. He told a conservative Christian radio host this year that as an addicted and troubled young man he had undergone a “spiritual awakening” and “knew he had to change at a deep, fundamental way.”

Yet Mr. Kennedy’s early fight for sobriety was far from the end of his battles with demons and self-destructive impulses. An examination of his life, gleaned through interviews with more than a dozen people, court filings and his own statements, reveals his distinct pattern of cycling through extremes — including his early drug addiction, compulsive sexual behavior and deep dives into conspiracy theories — all while under the microscope of fame.

At midlife, Mr. Kennedy won public acclaim as a crusading environmental lawyer who sued corporate polluters, cleaned up rivers and lobbied to protect New York’s drinking water. But he was also a serial philanderer who kept a journal chronicling his encounters and assigned numerical scores to women, even as he berated himself for his inability to control his actions.

His infidelities contributed to the breakup of his second marriage, according to interviews with people who knew the couple. A former nanny who worked for his family during this time also has accused Mr. Kennedy of making sexual overtures toward her and touching her without consent.