A THOUSAND GREAT comedies, from “Much Ado About Nothing” to “Annie Hall”, start off with characters whose flaws are making them miserable. The genius of “The Good Place”, the philosophical sitcom whose fourth and final season concludes on January 30th, is to make this self-inflicted torture an explicit part of its setup—indeed, of the structure of its universe. The protagonists, who at first believe themselves to have died and gone to heaven, discover at the end of the first season that they are actually in hell (or “the Bad Place”), having been selected by a demon for their ability to drive each other up the wall. Eventually they and the demon team up on a quest for moral improvement and start exploring the work of various philosophers, and the series becomes a sort of psychedelic Bildungsroman.

Television has never seen anything like “The Good Place”; playing Sartre’s “hell is other people” for laughs is just the start. But for all its originality, there is something about the series that feels very old. With its fantastical setting, thinly grounded plot twists and interventions by supernatural beings, it often seems to hark back to the drama of the Middle Ages or of classical antiquity. Comedies that start with characters torturing themselves and move towards an epiphany in which all turns out for the best have been performed since the Greeks. “The Good Place” torques up the stakes more than usual—by the finale, the protagonists are expected to come up with an improved system of moral evaluation for humankind, lest the universe be rebooted. But much of what the series does is what comedy has been doing since it was invented.

Take “Heauton Timorumenos” (“The Self-Tormentor”), written by the Roman playwright Terence in about 160BC. Like “The Good Place”, it is built around star-crossed couples and a case of mistaken identity. The self-tormentor of the title, the aging landowner Menedemus, has chewed out his son for falling in love with a poor girl; the son has run off to join the army, and now Menedemus is punishing himself for being too strict. The son’s best friend, meanwhile, is besotted with a flashy courtesan. In the end, after the intervention of a cunning slave (a stock type in classical comedy), all is resolved happily. The poor girl turns out to be the best friend’s sister, abandoned at birth and believed dead. Menedemus and his son are reconciled, and both couples are united.

Menedemus represents a crucial figure in comedy: the senex, the old man who prevents young lovers from getting together. In “The Good Place”, this role is initially filled by Michael, the demon in charge of the operation (played by Ted Danson). Michael at first claims to have matched the series’ romantic couples as each others’ “soulmates”, when in fact he has set them up to torment each other. But the joke, as always in comedy, is on the senex: one couple really are soulmates. With the help of, yes, a cunning slave (in this case an all-knowing database named Janet), they turn his scheme upside-down.

As for the couples, they serve the function of juxtaposing character types. The lead pairing consists of Chidi (William Jackson Harper, pictured), an indecisive moral-philosophy professor, and Eleanor (Kristin Bell, also pictured), a hard-drinking misanthrope. She thinks she has landed in the real Good Place by mistake and begs Chidi’s help in learning ethics to avoid discovery, thus gradually becoming a better person. The second couple, in turn, serves as a foil to the first. Eleanor’s solipsism contrasts with the neediness of Tahani (Jamila Jamil), a name-dropping socialite. Chidi, the paralysed intellectual, is set against Jason (Manny Jacinto), a genial DJ so impulsive as to be idiotic.

This device of contrasting couples, too, is an ancient one. Some classicists believe it was invented by Terence, who wrote of his discovery of the “doubled” plotline. In “The Self-Tormentor” he uses it to explore themes such as filial piety versus romantic loyalty, or modesty versus glamour. Half of Western comedy from the Renaissance to Hollywood (“Much Ado About Nothing” and “Annie Hall” included) features something similar.

Obviously, there is plenty in “The Good Place” that does not fit into ancient Roman literary structures. Chidi and Eleanor’s relationship adheres to a dramatic form that seems to have developed much later: the love-hate, will-they-won’t-they romance. (Beatrice and Benedick in “Much Ado About Nothing” might be the original example.) Mr Danson got his start in the 1980s as half of one of the great will-they-won’t-they couples, playing Sam to Shelley Long’s Diane on “Cheers”. It is a nuanced pleasure to watch him preside over a 21st-century version.

But the most important link between “The Good Place” and the comedy of antiquity lies in its treatment of moral philosophy. It can be harder to spot philosophical questions in comedy than in tragedy, mainly because the happy endings tend to obscure the dilemmas. The characters in “The Self-Tormentor”, for example, are constantly turning to the audience to ask whether they are doing the right thing. Menedemus worries that forgiving his son for falling in love with an indigent girl will turn the boy into a spoiled wastrel. His neighbour Chremes, who thinks Menedemus’s self-flagellation pointless, wonders whether it would be ethical to trick his friend into behaviour that will make him happy.

One person who took the philosophy of classical comedy seriously was Northrop Frye, a mid-20th-century literary critic. For Frye, comedy was the dramatic form through which the Greeks and Romans imagined how humans, with all their flaws, could be reconciled with the stringent demands of ethical norms and virtues. He located comedy’s essence in a famous line from “The Self-Tormentor”: “Nothing human is alien to me.” This is actually Chremes’s justification for butting into Menedemus’s business, but Frye and others have taken it more broadly, as a battle-cry for humanist ethics.

Michael Schur, the creator of “The Good Place”, has said the show grew out of an urgent sense that the complexity of modern society means individuals must confront ethical questions which they lack the philosophical tools to address. Terence, too, would have felt the need for a philosophy that could deal with cultural confusion. Born in North Africa, he came to Rome at a time when the Mediterranean was awhirl with competing civilisations: Carthage, Seleucid Syria, Ptolemaic Egypt. Even as “The Self-Tormentor” played in Rome, the Maccabees in Jerusalem were staging the first great conflict between Greco-Roman society and monotheism.

The ancient world’s ethical mess would eventually lead Rome to embrace a universalistic creed based on forgiveness, whose central story was the biggest comedy of all—one which Dante would later call “divine”, and which tacked a happy ending onto both the history of the universe and death itself. Four seasons of “The Good Place” have produced as many absurdities and contradictions as any other philosophical system. But the gags have generally been better.