Over the past 18 months, NBC’s “Community” has had to deal with a public dissing of the sitcom by its biggest star, Chevy Chase, who eventually left the show, and the unceremonious dumping of creator Dan Harmon, a mad genius who used social media once too often to throw his temper tantrums.

The behind-the-scenes hoopla may have plagued the show – but it also may have saved it.

“In a weird way, the drama behind the stage was sort of keeping ‘Community’ on people’s minds,” said Jim Rash, who plays the community college’s flamboyant principal.

Rash returns for the fifth-season premiere Thursday, as does Harmon, whose comeback once seemed less likely than another season of football from Brett Favre.

The survival of “Community” might seem inexplicable, considering its low ratings – even in its best season, it ranked only 97th among prime-time shows. But it kept getting a reprieve because the struggling network didn’t have anything else to put in its place. There’s also motivation for Sony, the company that produces the show, because “Community” is just four episodes shy of 88, the unofficial total that makes a series viable for the highly profitable world of syndication.

Harmon’s Lazarus act is more of a head scratcher. This is, after all, a man who spent part of his hiatus comparing NBC President Bob Greenblatt to Darth Vader and describing his Sony bosses as inhuman.

Much of the credit goes to series star Joel McHale, who worked as chief negotiator over a series of lunches. Then there’s the fact that the fourth season, under the guidance of David Guarascio and Moses Port (“Just Shoot Me,” “Happy Endings”), failed to capture what made “Community” so special: the ability to place relatable characters in a unique, often surreal world every week. Under the temporary team, it was a pleasant sitcom. Under Harmon, it was the edgiest, most unpredictable program on network television.

“Like with ‘Breaking Bad’ or ‘Arrested Development,’ you need that where-it-came-from place,” said McHale, whose character, the self-centered Jeff Winger, returns to school this season as a teacher rather than a student. “We had some really good stuff last year, but it did not have the direction that most other seasons had.”

The sitcom, which got only a 13-episode pickup this season, will get back to pushing the envelope with a trip into David Fincher’s imagination, a “Logan’s Run” tribute and a follow-up to the classic Dungeons & Dragons episode. There’s also a madcap roster of guest stars, including songwriter Paul Williams, Chris Elliot, “Justified’s” Walton Goggins, Gina Gershon, “Breaking Bad” creator Vince Gilligan and a cameo that’s so weird, you’ll be questioning your own sanity.

Harmon seems well aware that his dedication to pop culture minutiae may alienate the masses whose idea of high-brow wit is grandma passing gas. He just doesn’t care.

“I would rather die than make bad stuff for people, because I’m a terrible dishwasher and a terrible lover and a terrible pet owner and this is my only recourse to go to bed at night and feel like I did anything of merit,” he said. “That fills me with emotions that sometimes get expressed in ways that you may read about in third-hand blogs and stuff, but overall, it allows me to fail upward.”

And if fans wail that the new batch of episodes don’t have the same beautiful insanity of the early years? Well, that’s fine, too.

“If I had not gone back, the worst-case scenario is me spending the next 30 years wondering what would have happened if I had gone back,” Harmon said. “If I do go back, the worst-case scenario is one crappy season. Who cares?”