Thirty years ago, comedian Bill Cosby was so beloved — so funny — that an admiring world threw millions in cash his way.

Cosby was the highest-paid entertainer in 1987, according to Forbes magazine, which estimated he made an astounding $100 million that year, including international syndication rights to his phenomenally popular “The Cosby Show.”

He was so rich, years later he even tried to buy the show’s network, NBC.

Those dizzying career heights stand in stark contrast to Thursday’s conviction on three counts of sexual assault — and the threat of serving prison, at age 80, for as long as 30 years.

Cosby started out as a pioneer, a kid from the north Philadelphia projects who happened to be funny.

After stints in the Navy and at Temple University on the GI Bill, he found his comedic footing in the early ’60s at the Gaslight Cafe in the Village.

Where other black comedians — notably Dick Gregory — were gaining fame with cutting racial commentary, Cosby kept it clean and quirky, creating that shrugging, lovable public persona he’d maintain for the next half-century.

“Make sure that you do things so that your name becomes a household word,” Cosby once recounted Gregory counseling him.

At first, he made $125 a week and lived over the Gaslight’s performance space in a storage room. Soon, though, his act won him recording deals and bookings across the country, and a TV appearance got him noticed by producer Sheldon Leonard.

In 1965, Leonard did something radical, casting Cosby alongside Robert Culp in the hit secret-agent buddy series, “I Spy.”

Cosby’s Scotty was the brains of the team, a multilingual Rhodes scholar who served as a foil to Culp’s more volatile playboy character, Kelly.

The combination in its day was so revolutionary that at first stations in Georgia, Florida and Alabama turned the show down.

“A black man and a white man were co-starred as equals on a positive level,” Culp recalled in a 2014 PBS interview.

“No one had ever done that before, ever, going all the way back to the Greeks.

“That’s how much of a groundbreaker Bill was,” Culp added.

He also kept refining and recording his comedy. In one retroactively creepy bit from his 1969 album, “It’s True! It’s True!” Cosby jokes about a mythical potion called “Spanish Fly,” one drop of which would render a female unfailingly amorous.

He’d reprise the Spanish Fly bit throughout his stand-up career.

“Put it in a drink . . . The girl would drink it, and . . .” Cosby told Larry King in a 1991 interview.

“And she’s yours,” King answered.

“Hello, America,” Cosby replied.

The date-rape drug bit would resurface and be used against him.

Last year, prosecutors in Montgomery County in suburban Philadelphia would ask, though without success, to enter into evidence Cosby’s many mentions of drugging women for sex.

Cosby was at the time about to go on trial for aggravated indecent sexual assault. That trial, for attacking Temple University basketball team manager Andrea Constand in 2004, would end in mistrial; it took a second jury to convict him Thursday.

Cosby’s climb to fame was just beginning as the “I Spy” series ended in 1968. Next was a two-season sitcom called “The Bill Cosby Show,” and then, in 1972, with a cartoon that would become a Saturday morning staple — “Fat Albert and the Cosby Kids,” which ran until 1979.

“Hey! Hey! Hey!” was Fat Albert’s signature call — which Cosby once credited to the rotund character’s dream of becoming a Temptations backup singer.

“Hey! Hey! Hey!” Cosby himself would call out last year, loudly and bizarrely, as he was escorted from court after the second day of deliberations on the first indecent-assault trial.

“The three most believable personalities are God, Walter Cronkite and Bill Cosby,” Anthony Tortorici, director of PR for Coca-Cola, quipped in 1981, as the comedian’s lucrative career as an advertising pitch man — for Jell-O, Coke, Kodak, Texas Instruments and other products — took off.

“During his 14-year reign over the ad industry’s public-approval index” only the pope was more popular, Advertising Age would write in 2003. A seemingly faithful marriage to wife Camille since 1964 only added to his wholesome persona.

Cosby struck it big in 1984, when “The Cosby Show” debuted and caught fire — and the fustily sweatered “America’s Dad” Dr. Heathcliff Huxtable beamed into millions of homes.

The Huxtable family “forced white America and black America to recognize the black upper-middle class,” Malcolm-Jamal Warner, who played son, Theo, noted in 2016 of the eight-season run.

“The greatest aspect of this legacy is that people around the world saw themselves in people who don’t necessarily look like them or live like them,” Phylicia Rashad, who played wife, Clair Huxtable, told Oprah Winfrey last year.

“I met Nelson Mandela,” she added. “He said, ‘I watched your show from Robben Island. I watched it with my guard, and it softened him.’ ”

The show would go off the air in 1992, with Cosby a rich man. He had an estimated personal wealth of $300 million.

He was so wealthy, in fact, that the same year, Cosby tried to buy the show’s host network, NBC, from owner General Electric. It was NBC that had hosted Cosby’s biggest moneymakers, “I Spy” and “The Cosby Show.”

The deal, in which Cosby would be a part owner, fell through. The asking price was estimated at the time to be $4 billion.

He spent the ’90s and 2000s writing, selling Jell-O pudding pops, touring his stand-up act to packed audiences and developing a series of film and TV ventures, including a Nickelodeon series called “Little Bill.”

In November, 2014, Cosby was on the brink of launching and starring in a new family sitcom, again on NBC, when the sex-assault scandal broke.

Multiple women, including model Janice Dickinson, came forward with chilling stories of being drugged and assaulted by the star — including at the height of his “Cliff Huxtable” fame. NBC promptly dropped plans for the new show, and Cosby has been industry Kryptonite ever since.

On Thursday afternoon, moments after the verdict, one of the last stations to run “The Cosby Show” reruns, the Atlanta-based Bounce network, dropped the show.

Additional reporting by Michael Starr