Perry Mason, the defense attorney hero of Erle Stanley Gardner’s legal thrillers (which have sold some 300 million copies since first debuting in 1933), has been ripe for a remake for a long time. After some movie adaptations and a long-running radio serial, it was the TV version, which premiered in 1957 and starred Raymond Burr, that determined what our courtroom dramas would look like for decades to come.

From avid armchair detectives to Supreme Court justices, everyone loves Perry Mason, right? But what did we ever really know about the guy, other than he almost always won his cases? Gardner, who died in 1970, wasn’t inclined to give Perry much of a backstory — believing, perhaps, that too much personality interfered with the formula. Perry was forever right and could always dig up the evidence to prove his case at the last minute. He’s a classic character, with all the dimension of cardboard.

That’s why Rolin Jones and Ron Fitzgerald’s superb new “Perry Mason,” an eight-episode series premiering Sunday on HBO, is the perfect lesson in how to update an icon, honoring the character by giving him the emotional depth and complexity that he previously never had.

Don’t get the wrong idea. The Perry Mason we meet in this version isn’t a pushover. As played by Matthew Rhys (“The Americans”), this Perry is a day-drinking (and night-drinking), underemployed private investigator who gets into plenty of unseemly scrapes. He makes his living, barely, by surreptitiously taking pictures of movie stars in flagrante delicto, in violation of moral clauses in their contracts; the studios then pay Perry to make the photos go away.

Perry’s wife (Gretchen Mol) left him and took their young son with her. He clings to what’s left of his deceased parents’ defunct dairy farm on the outskirts of a rapidly expanding — and always corrupt — Los Angeles. He’s also suppressing some pretty intense trauma from his time on the French battlefields in World War I.

The series opens right after Christmas 1931, with the gruesome death of “Baby Charlie” Dodson, who was kidnapped for ransom. The baby’s grieving parents, Matthew and Emily Dodson (Nate Corddry and Gayle Rankin), have tenuous ties to a popular church headed by a dynamic radio evangelist named Sister Alice McKeegan (“Orphan Black’s” Tatiana Maslany), and it isn’t long before the cops and a prosecuting attorney (Stephen Root) are determined to pin blame for the baby’s murder on the parents, who then turn on each other. The bold type of the daily headlines about all this couldn’t get any bigger.

Defense attorney E.B. Jonathan (John Lithgow) and his loyal office assistant Della Street (Juliet Rylance) take on Emily Dodson’s case. Jonathan hires Perry, as he often does, to poke into the bungled kidnapping and find what the cops missed — which, whaddya know, turns out to be plenty.

“Perry Mason” perfectly and methodically lays out a compelling and expanding mystery (which is, after all, the main attraction in a genre story), while giving remarkable shape to characters whose stories will resonate with a modern audience — such as Paul Drake, a black LAPD patrolman (Chris Chalk from “When They See Us”) mistreated by his white peers; or the good-humored coroner (Jefferson Mays) who lets Perry have an unofficial look at relevant stiffs in the city morgue. Shea Whigham (“Boardwalk Empire”) is also fantastic as Perry’s occasional hired help, Pete, as is Lili Taylor, playing Sister Alice’s controlling mother, Birdy.

Rhys brings a natural ease to playing this rougher, tougher Perry. I mean, Matthew Rhys really is the most, isn’t he? Able to simmer and seethe as a man down on his luck, but just as often hilariously wry. An early sex scene — between Perry and his aggressive lover, a biplane pilot named Lupe (Veronica Falcón) — is a painfully funny departure from HBO’s usual erotic romps. Not a drop of talent is wasted here, whether in Lithgow’s heartbreaking portrayal of a lawyer past his prime, or in Maslany’s unsettling depiction of a spiritual leader on the brink of divine madness.

Besides its slow, thoroughly satisfying build as a whodunit, the series ably handles a thematic tension between vile darkness and moral courage. “Perry Mason” is a worthy origin story, and it’s especially stirring when Perry at last begins to realize the power contained in the law, and his own arc bends toward justice.

Perry Mason (one hour) premieres Sunday at 9 p.m. on HBO.