When it came to sex and drugs, rock ‘n’ roll legend Chuck Berry rang all the bells — and then some.

Berry, who died of natural causes on Saturday at age 90, is widely credited with helping create rock ’n’ roll in the 1950s with a string of hits including “Johnny B. Goode” and “Roll Over Beethoven.”

But he would come to set a standard for rock-star depravity that few of his disciples would hope — or even want — to match.

Following two trips to the slammer — first at the height of his fame in the early 1960s for transporting a 14-year-old girl across state lines for sex, and again in 1979 for tax evasion — Berry was busted over a 1990 drug raid on his estate in Wentzville, Mo.

Although authorities suspected him of transporting huge loads of cocaine in his guitar case as part of a multimillion-dollar drug operation, the search only turned up about two ounces of pot, some hashish, two rifles and a shotgun, as well as more than $122,000 in cash.

But the cops also found a huge stash of pornography, including dozens of videotapes, trays of photographic slides and books — some of which appeared to show underage girls.

Berry, who publicly denied ever using coke, was charged with pot possession and three counts of child abuse for the underage porn.

He sued the county prosecutor, William J. Hannah, accusing him of filing malicious and politically motivated charges, and later cut a no-jail plea deal in which the child-abuse charges were dismissed and he dropped his civil case.

The seizure of Berry’s porn collection, however, led to a scandalous 1993 report in the since-defunct Spy magazine that went way beyond the earlier scandals — revealing a penchant for sexual fetishes involving bodily excretions and a predilection for spying on women in bathrooms.

The magazine described a homemade video in which Berry and “an attractive blond white woman” both relieved themselves during a New Year’s Eve romp in the bathroom of a hotel suite in Lake Tahoe, Nev.

The report also detailed how Berry allegedly installed hidden cameras in the women’s restroom at the Southern Air restaurant in Wentzville after he bought it in 1987. One camera “was evidently behind the toilet seat,” according to Spy, while others captured “aerial views of the toilets’ contents during the seconds after the women stood but before they flushed.”

The recordings were then reportedly “painstakingly” edited and compiled in a pair of “toilet tapes” that showed hundreds of women and girls “in the act of relieving themselves.” “Sometimes the frame is frozen for a few seconds, lingering on moments that must have been considered particularly moving,” Spy reported.

In 1994, Berry settled for $830,000 a class-action suit filed by dozens of women who claimed they had been taped using the bathroom, and also settled a similar suit filed by a former restaurant worker and another woman for $310,000.

Berry was also publicly shamed when the High Society nudie magazine in January 1990 published photos of him posing naked with different women, with the publication claiming to be “the only magazine with the balls to show Chuck’s berries.”

The “School Days” singer’s first brush with the law came as a youth, when he was sent to reformatory for three years for pulling off an armed carjacking with a pair of buddies.

After getting sprung, he got a cosmetology degree and worked as a beautician, and in 1948 married Themetta “Toddy” Suggs, with whom he had four kids.

His music career began in the early 1950s. Berry scored his first hit in 1955 with “Maybellene.”

But by 1959, he was in trouble again, busted over a racially charged incident at a dance at the Meridian, Miss., high school.

According to Berry’s autobiography, “one of the girls threw her arms around me and hung a soul-searching kiss that I let hang a second too long.”

Someone shouted out that “this n—-r asked my sister for a date!” and a mob chased him outside, where the cops caught him hiding in a nearby building.

Berry was charged with disturbing the peace — which he settled by spending a night in jail and surrendering the $700 seized from his pockets.

That incident paled in comparison, however, with the case brought later that year, when he was charged with violating the federal Mann Act — also known as the White Slave Traffic Act — which prohibits transporting women across state lines for “prostitution or debauchery, or for any other immoral purpose.”

The victim in question was a 14-year-old waitress and prostitute whom Berry picked up while traveling in Mexico and brought back to St. Louis to work as a hostess at his Club Bandstand nightclub.

Berry — who later claimed the girl told him she was 21 — fired her after several weeks, after which she was busted for prostitution and told the cops that Berry repeatedly had sex with her while they were on the road, including in the back of his Cadillac.

Berry was convicted by an all-white jury and sentenced to the maximum five years in the slammer by Judge George Moore, who told him “I have seen your kind before” and denied him bail pending appeal.

“I would not turn this man loose to go out and prey on a lot of ignorant Indian girls and colored girls, and white girls, if any,” he added.

The conviction was overturned based on racist remarks made by the judge, but a second jury also convicted Berry and he wound up serving 20 months behind bars, during which time he wrote several songs.

The lyrics to one of them, the 1964 widely covered “Promised Land,” recount a cross-country trip from Norfolk, Va., to Los Angeles — even though Berry said prison officials “were not so generous as to offer a map of any kind, for fear of providing the route for an escape.”

Berry ran afoul of the law again in 1979, when he was slapped with tax charges and quickly struck a plea deal in which he admitted cheating the feds out of $110,000 in income taxes.

He twice broke into tears during his sentencing, at which the judge slapped him with 120 days behind bars and four years’ probation.

The court session came little more than a month after Berry had entertained then-President Jimmy Carter and his family on the lawn of the White House.

‘Those who knew him well told me about what a wonderful family man he was. He was a walking contradiction, that’s for sure.’ - Bruce Pegg on Chuck Berry

Years later, Berry admitted the tax case “was no bum rap” — but claimed that the government had inflated its losses.

“It was straight, true. It was a bum rap in the sense that . . . it was about 15 percent that they added, but that’s nothing to kick about,” he told Goldmine magazine. “In other words, they were about 85 percent right and 15 percent wrong.”

Berry long cultivated a reputation as a cheapskate, in large part because he used local “pick-up” bands while on tour instead of hiring regular performers, often resulting in sloppy performances with the musicians he met just moments before hitting the stage.

In 1987 — a year after his induction into the Rock & Roll Hall of Fame — he even admitted that he became a rock ‘n’ roller for the money, and that “the Big Band era is my era.”

“Rock ‘n’ roll accepted me and paid me, even though I loved the big bands,” he told the Los Angeles Times.

“I went that way because I wanted a home of my own,” he said. “I had a family. I had to raise them. Don’t leave out the economics. No way.”

Later that year, Berry was accused of punching a woman in the mouth during an early morning dispute at the Gramercy Park Hotel.

Friends described victim Marilyn O’Brien Boteler as a 30-something rock singer who dated Berry — whom she slapped with a $5 million suit that claimed she needed five stitches as result of the smack.

Berry was also charged with assault but failed to appear in court in June 1988, leading to a bench warrant for his arrest.

He later plea-bargained to a lesser charge of harassment and was sentenced to a $250 fine.

Author Bruce Pegg, who wrote a 2002 biography titled “Brown Eyed Handsome Man: The Life and Times of Chuck Berry,” described the musician as a complicated man.

While Pegg said he believed the Mann Act conviction “was racist in nature” and the videotape scandal “began with a personal grudge,” he also said Berry was no saint and someone who “kept on giving everyone a 2-by-4 big enough to hit him with.

“Yet at the same time, those who knew him well told me about what a wonderful family man he was,” Pegg added.

“He was a walking contradiction, that’s for sure.”