The show, like “Parks and Recreation” before it, reflects its political era. Illustration by Nick Little

“I was dropped into a cave, and you were my flashlight,” Eleanor Shellstrop, a bad person, says to Chidi Anagonye, her tutor in morality.

This Platonic declaration of love shows up in the finale of the sitcom “The Good Place,” but it winds up illuminating everything around it. The NBC comedy, which was created by Michael Schur, débuted in September, then went on hiatus just before the election, returning in January—when it ran a mere four more episodes, thirteen total, a rarity for network television. The finale aired the night before Trump’s Inauguration. Many fans, including me, were looking forward to a bit of escapist counterprogramming, something frothy and full of silly puns, in line with the first nine episodes. Instead, what we got was the rare season finale that could legitimately be described as a game-changer, vaulting the show from a daffy screwball comedy to something darker, much stranger, and uncomfortably appropriate for our apocalyptic era. Take that, “Westworld.”

The first show that Schur created, “Parks and Recreation,” also on NBC, had its own first-season game-changer: it pivoted from mocking the small-town liberal bureaucrat Leslie Knope (Amy Poehler) to embracing her as a utopian idealist. Pawnee, Indiana, where Knope helped run the Parks Department, was a depressed, dysfunctional city just south of the Rust Belt. The press was toxic, the representatives corrupt. But Knope and her team kept trying to fix it anyway, because they shared some basic values: honesty, hard work, and a sweet faith in community. In the show’s finale, in 2015, Knope—whose tribulations eerily presaged those of Hillary Clinton, down to a hacking scandal—was headed to the White House, her steely sunshine having warmed her friends’ lives, from her libertarian boss to her cynical millennial intern. It was a valentine to the squeaky wheel.

That was then; this is now. “The Good Place” introduced itself as very much a follow-up to “Parks and Recreation,” only more surreal and high-concept. The first episode is about a selfish American jerk, Eleanor (the elfin charmer Kristen Bell), who dies and goes to Heaven, owing to a bureaucratic error. There she is given a soul mate, Chidi (William Jackson Harper), a Senegal-raised moral philosopher. When Chidi discovers that Eleanor is an interloper, he makes an ethical leap, agreeing to help her become a better person, tutoring her with T. M. Scanlon’s “What We Owe to Each Other.” These secret lessons pay off, and the show evolves into a charming, if chaotic, romantic farce, in which Eleanor and Chidi—plus another stealth bad person, a wannabe d.j. from Florida named Jason Mendoza, and his own wrong soul mate, Tahani, a celebutante-philanthropist—slam doors and trade partners, all the while exploring questions of what goodness really means.

“The Good Place” kept complicating the physics of its absurdist premise: there was a “Bad Place,” too, full of partying devils, a wonky artificial intelligence named Janet, and endless jokes tweaking the heavenly cul-de-sac’s progressive-conformist, frozen-yogurt-heavy vision of the good life. (“Fuck” is censored to “fork”; arson lowers your virtue rating, but so does paying to see the Red Hot Chili Peppers.) Overseeing it all was Michael, an adorably flustered angel-architect played by Ted Danson; like Leslie Knope, he was a small-town bureaucrat who adored humanity and was desperate to make his flawed community perfect. “You know the way you feel when you see a picture of two otters holding hands? That’s how you’re going to feel every day,” he promises the newly dead during orientation.

After watching nine episodes, I wrote a first draft of this column based on the notion that the show, with its air of flexible optimism, its undercurrent of uplift, was a nifty dialectical exploration of the nature of decency, a comedy that combined fart jokes with moral depth. Then I watched the finale. After the credits rolled, I had to have a drink. While I don’t like to read the minds of showrunners—or, rather, I love to, but it’s presumptuous—I suspect that Schur is in a very bad mood these days. If “Parks” was a liberal fantasia, “The Good Place” is a dystopian mindfork: it’s a comedy about the quest to be moral even when the truth gets bent, bullies thrive, and sadism triumphs.

So, spoilers. In the final episode, we learn that it was no bureaucratic mistake that sent Eleanor to Heaven. In fact, she’s not in Heaven at all. She’s in Hell—which is something that Eleanor realizes, in a flash of insight, as the characters bicker, having been forced as a group to choose two of them to be banished to the Bad Place. Michael is no angel, either. He’s a low-ranking devil, a corporate Hell architect out on his first big assignment, overseeing a prankish experimental torture cul-de-sac. The malicious chuckle that Danson unfurls when Eleanor figures it out is both terrifying and hilarious, like a clap of thunder on a sunny day. “Oh, God!” he growls, dropping the mask. “You ruin everything, you know that?”

Michael’s goal is to get his charges to torture one another so that he can watch, mainly for kicks—he’s a reality-TV producer, essentially. That’s why the soul mates are mismatched; that’s why the vain, needy Tahani is there in the first place. (Possibly, that’s why there’s so much frozen yogurt.) As in “The Truman Show,” every resident other than the central quartet has been playacting. These characters are not locked in a good system gone wrong. They’re locked in an evil system gone accidentally right.

Worse, now that his experiment has crashed, Michael plans to erase the ensemble’s memories and reboot. The second season—presuming the show is renewed (my mouth to God’s ear)—will start the same scheme from scratch. Michael will make his afterlife Sims suffer, no matter how many rounds it takes.

Schur has told reporters that he based “The Good Place” in part on “Lost,” and, early on, it was easy to imagine that he simply meant “sprinkled with amusing flashbacks that deepen the characterizations.” Instead, he had a bigger puzzle-box narrative in mind, one that plays on the viewer’s delusions as well as those of the characters. Everyone loves an ensemble full of potential soul mates; a lot of the appeal of “Parks and Recreation” was watching lovers pair up, two by two. It was easy to luxuriate in the gentrified fantasy of the Good Place itself, a kind of gated community for the virtuous. There was something warped about the details—would Heaven really be so mall-like, so blandly Whole Foods?—but it was easy to shrug off the discomfort as the growing pains of a new sitcom. This lent a double whammy to the reveal, since it forced us to grieve for our own naïveté. We were suckers, too.

When the switch flipped, the premise deepened. Most notably, it became clear that Eleanor was the show’s perverse hero—it was her inability to fake politeness, her crude candor, that enabled her to hack Hell. By confessing her flaws, and begging Chidi to help her change, she undermined Michael’s plan. On earth, Eleanor might have been a selfish loner, but in Hell she was an existential rebel, the woman who found a way to get kinder in a system designed to make her mean.