In its fantastic second season, NBC’s “The Good Place” found empathy within the devil.

Michael (Ted Danson), an immortal bureaucrat charged with torturing four souls in The Bad Place — a version of hell where his prisoners are meant to inflict their neuroses on one another — develops a conscience and helps them escape.

While they argue their eternal cases in front of an omniscient judge (Maya Rudolph), Michael explains himself to his infernal supervisor. “I was just trying to prove that humans could be made to torture each other,” he says. “Instead, they helped each other. They were bad people. This wasn’t supposed to be possible.”

People never learn, people don’t get better: These are unsurprising beliefs from a minion of hell. But they’ve also been the guiding principles of the last two decades of TV. From the dawn of “The Sopranos” through the rise of Netflix, acclaimed antihero dramas have focused on bad people getting worse or good people going bad. (In “Breaking Bad,” the concept is right in the title.)

There are many delights to “The Good Place,” which ends its too-short 13-episode season Thursday: its ingenious twists, its riffs on the banality of damnation. (Hell is stocked with Hawaiian pizza and plastered with movie posters for “Pirates of the Caribbean 6: The Haunted Crow’s Nest or Something, Who Gives a Crap.”)

But the most refreshing thing about “The Good Place,” in an era of artistic bleakness, is its optimism about human nature. It’s made humane and sidesplittingly entertaining television out of the notion that people — and even the occasional immortal demon — are redeemable.

For a generation now, the moral journeys of TV’s best shows have mostly run in the other direction. Tony Soprano spent six seasons in therapy yet learned nothing except how to be a better criminal. The corrupt police officer Vic Mackey, in “The Shield,” rationalized his brutality as what it took to bust gang members.

The exceptions — ambitious series about people seeking grace and improvement like HBO’s “Enlightened” and Sundance’s “Rectify” — tended be overshadowed. Sunnier sitcoms like “Parks and Recreation,” from “The Good Place” creator Mike Schur, dealt with characters who were already decent, not striving to become that way.

Over time, antihero culture spread from premium cable to the mainstream. The bristly protagonists of Fox’s “24” and “House, M.D.” broke rules to get the job done. Reality TV made stars of people who, in the credo of that genre, weren’t there to make friends. Antiheroes are de rigueur in noirish streaming dramas like “Bloodline” and “Ozark.”

None of this is to say that antihero stories are necessarily amoral. Some, like “Breaking Bad,” assumed moral universes of retribution and consequences. But they were a kind of rebellion against the pat moral lessons of earlier TV, in which you could count on the good guys to win simply because they were good.

“The Good Place,” on the other hand, avoided falling into easy moralizing by committing to the idea that becoming good is hard work.

This was built into the structure of “The Good Place.” For most of the first season, Eleanor Shellstrop (Kristen Bell), a selfish ne’er-do-well, believes — as part of Michael’s ruse — that she’s in heaven and was placed there by mistake. So she gets her assigned “soul mate,” the moral-philosophy professor Chidi Anagonye (William Jackson Harper), to teach her to be a better person.

The result is a running crash course in remedial ethics, with the most madcap name-dropping of the greats of moral thought since Monty Python’s “Bruces’ Philosophers Song.” (“The Good Place” has something in common with the absurdist, meaning-of-life-obsessed humor of the 1970s, like Python and “The Hitchhiker’s Guide to the Galaxy.”)

In a Season 2 episode, for instance, Chidi brings up the “trolley problem,” a thought experiment devised by Philippa Foot: You’re driving a trolley and must either continue on the track and kill five people or switch tracks and kill one. Is it better to kill five innocents through inaction or one by choice?

To give the conundrum some oomph, Michael conjures up an actual trolley, forcing Chidi to live out his dilemma over and over, complete with copious blood spatter. The scene is slapstick, gross-out brilliance — and a clever illustration of how applying hypotheticals to real life (or a convincing illusion) becomes, er, messy.

The characters of “The Good Place” ended up in hell for relative misdemeanors. Eleanor is an oaf, but hardly a murderer. Tahani (Jameela Jamil) is a vain social climber with a jealous streak; Jason (Manny Jacinto) is a sweet dimwit. Chidi’s sins are intellectual paralysis and self-flagellation. (When he learns he’s in hell, he assumes it’s for drinking almond milk: “I knew it was bad for the environment, but I loved the way it coated my tongue with a weird film.”)

This may seem unfair — is anyone good enough for The Good Place? — but it serves a purpose. It’s easy to feel distance from a true monster like Tony Soprano. The characters on “The Good Place,” on the other hand, have everyday failings. They have work to do — just like we do.

In “The Good Place,” morality is not something you have; it’s something you do. It’s a muscle that requires exercise. The show shares with dramas like “Breaking Bad” the belief that being good is hard. But it doesn’t believe that being good is futile.

The series feels like part of a wider reaction against the dark TV view of human imperfection, something that was once groundbreaking but has become a commodity.

CBS All Access’ “The Good Fight, ” like its predecessor “The Good Wife,” is about the conflict between principle and the cynical practice of law. ABC’s “The Good Doctor” (anyone notice a pattern in the titles?) is a sort of syrupy reverse “House” in which the diagnoses come not from a misanthrope but a well-meaning autistic savant.

But the upbeat sophistication of “The Good Place” is still rare, in this world and, apparently, in the next. When Ms. Rudolph’s judge agrees to hear the characters’ case, she says that she’s only doing it out of boredom. “It’s either this,” she says, “or start ‘Bloodline.’ ”