SPOILER ALERT: Do not read if you have not yet watched the series finale of “The Undoing.”

When Hugh Grant’s wife, Anna Eberstein, saw an early cut of his latest television project, HBO’s “The Undoing,” she told him she wanted the couple at the center of the story to get back together — something he considers “quite an interesting instinct,” given all they go through in the six-episode series from executive producer and writer David E. Kelley, and executive producer and director Susanne Bier.

This was before she knew that one half of the couple, Grant’s Jonathan Fraser, was in fact Elena’s (Matilda De Angelis) murderer, though — a truth revealed in the finale episode aptly titled “The Bloody Truth.”

Her reaction, Grant tells Variety, was initially that she hoped he was not the killer “because I think these two love each other and have something together.” But it also spoke to the integral “whodunnit” aspect of the six-episode series.

“From a practical point of view, to make the series work, he has to be as convincing as I can possibly make him when he’s protesting innocence and his love for his wife, his love for his kid. And then you ask yourself in the margin, ‘But what does he really feel?'” Grant says. “The real Jonathan, in my opinion, is incapable of admitting he killed this woman — to himself, even.”

“I did warn my wife. I said, ‘Look, there was a kind of highly characterized way I was thinking of playing it, but in the end, Susanne Bier wanted me to bring it back to one version: adult Hugh Grant for the last 10 years. You know, I have children, they go to a school rather like the school [in ‘The Undoing’], we go to fundraisers; there are parallels and I didn’t want my wife to suddenly think, ‘Christ, who have I married?'” Grant says.

But the “real” Jonathan, in Grant’s mind, was “self-delusional” and a sociopath, which is the fundamental way he got inside the character’s mind.

“The Undoing” was based on Jean Hanff Korelitz’s 2014 novel “You Should Have Known,” which was centered on Grace’s (Nicole Kidman) journey as a brilliant clinical psychiatrist who couldn’t — or wouldn’t — see the truth behind the cracks in her marriage and the psychology of her husband. For the series, Kelley expanded and altered the story to further flesh out the character of Jonathan.

“I think what’s interesting about her whole part, her role, is that despite all the evidence pointing to me as the killer and the certainty that I’m unfaithful and a terrible liar and a monster, really, without the murder, she loves him still and wants the marriage to work. That’s all so fascinating and, of course, it speaks to where the book really began because the book’s called ‘You Should Have Known’ and she should have known,” Grant says. “I’ve seen this with lots of couples where you think, ‘What the devil are you doing with her? Or what are you doing with him?’ They know the shortcomings intellectually, but they’ve filled in the gaps to make them someone they want. That shouldn’t be with Grace: She’s an expert shrink, she lectures people on [this]; right in Episode 1 she tells the woman, ‘You knew this man was no good.'”

Although there was source material on which Grant could draw if he wanted to, most of his research into the kind of man Jonathan was came from the scripts themselves, which he had upfront (“I don’t think I could have done it any other way,” he admits) and by meeting with real oncologists both in Britain and New York.

“It was clear to me where the character was going and then it was just about going back and creating the backstory,” he says. “The main thing is I do start with the script and breaking it down into tiny, tiny, tiny fragments and asking myself with each line, each thing they do, ‘Why? Why, why, why?’ And very often that triggers a whole succession of thoughts which enable me to fill in the blanks of the guy’s history. And so I create this enormous history on a computer, tens of pages long — a biography, really, from birth right through to the story as it appears at the beginning of the [project]. So I know all of his secrets. What’s interesting in a project like this is that process is not always identical to what a film needs in a given moment, especially when you’re dealing with whodunnits and mysteries, so sometimes there’s a clash between what the film requires and what you require as an actor, and the trick is to try and find a balance.”

Meeting with the doctors, he says, helped “get a sense of what made them tick and to just get the vibe off them because sometimes with doctors you think, ‘This guy’s a hero, he’s amazing, he saves lives,’ but he’s just a fraction too good to be true, and I was looking for that kind of doctor.”

Grant played Jonathan as a chameleon, adapting himself to the environment he was in and the people by whom he was surrounded. “My mother was a bit like that; I could tell who she was talking to on the phone because she was talking like them,” he shares. This meant he was often subtly shifting his body language, behavior and manner of speaking as an attempt to get what he needed out of those around him at any given moment, from being soft-spoken and sweet with his young patient, to pleading and apologetic with his wife when he returned to her after seeming to flee, to intelligent and authoritative when he was being interviewed by Connie Chung.

Jonathan was a “great savior” and “star of international medicine,” Grant points out — a pediatric oncologist who first met Elena when he was treating her son Miguel (Edan Alexander). But that inappropriate relationship with a patient’s mother got him fired from his New York hospital, and he kept both the job loss and the affair secret from Grace until he was exposed by the murder investigation.

“He’s just so narcissistic that he believes the real him is the marvelous Jonathan, the star of medicine and great dad and great husband,” Grant explains. “I think he absolutely lives off adoration, undiluted, unequivocal love.”

Killing Elena, after all, did come after a moment where he lost her unquestioning love and devotion. She told him she hoped his son Henry (Noah Jupe) would be “like a big brother” to Miguel, and he at first threatened to hurt her if she came near his family. When she questioned if he would, he banged her head into the wall a few times and started to leave her. She then picked up the sculpting hammer and charged him with it, which showed him just how far he had fallen in her eyes. He disarmed her and hit her with it so many times he couldn’t even claim self-defense if he was willing to admit he did it.

“I don’t think the violence he shows when he kills Elena is the first time it’s happened. I think there have been instances in his life before where it’s been hushed up,” Grant admits.

Reflecting on the tragedy of Jonathan’s little sister being struck and killed by a car while in his teenage care, Grant says, “I did once have an idea written in the margin of my script that maybe Jonathan loved being the single kid, apple of his parents’ eye, and when Katie came along he didn’t care for it much and possibly accidentally-on-purpose let her run out into the road. He might be that kind of kid.”

There were other flashes of Jonathan’s violent and self-serving capabilities throughout “The Undoing,” such as biting a prisoner’s finger or trying to put the murderous blame on his son. “He’s grasping at the very final straw and he knows it’s not going to go down well with Grace, but without that straw he’s sunk; he’s guilty, he’s finished. That’s what I remember thinking there. It’s a wonderful sequence, I think, because it’s just so sick to try and blame your son and then even better, the son overhears and you have to try and make good with your son. I remember thinking, ‘God this guy is fucked up,'” Grant says of the latter action.

Even in some takes of scenes with his on-screen family, Grant dialed up the tension. One version of him telling Henry to shut up in the car after Jonathan kidnapped him in the finale, for example, had Jonathan spewing, “Oh shut the fuck up, you little c—” at his son, he shares. “There were certainly other moments in the six episodes where I thought it would be a good moment to show a real flash of the true guy and his violence, but had we done it, the weight of evidence on Jonathan would be too heavy; we would have killed the whodunnit. The circumstantial evidence was already so huge even one more ounce of weight in that side of the scales would have tipped it.”

Even after Grace took the stand, revealing she had previously called him a narcissist (even though she claimed it was an “unofficial” diagnosis) and that his own mother shared with her that he never showed remorse after Katie died, Jonathan kept a relative cool. Rather than lashing out at Grace, he convinced Henry to skip school and “go to breakfast with him” before the verdict could officially come down. The two ended up on a road trip to upstate New York as Grace and her father (Donald Sutherland) chased them in a helicopter. Although Jonathan prepared himself to jump off a bridge, Grace calling for him to stop actually did get him to climb down.

“He knows he’s screwed by now and what I recall is he might be planning to jump off that bridge, he might not, but I think he wants to be the center of attention still. I don’t think it’s terrible news for him when all those helicopters appear overhead and the TV cameras and all that [show up]. He’s a narcissist and that never goes away: If he’s going to go out, he’s going to go out in a blaze of glory,” says Grant.

Grant also wanted to leave the audience lingering on how “sick” Jonathan really was in those final moments. “He still thinks it’s all going to be OK because he’s the great Jonathan Fraser and Grace is going to embrace him and say, ‘It’s all right,'” Grant says.

Of course, nothing could be all right because the moment he stepped down, the police had him in handcuffs and worse for Jonathan, Grace led his son away and wouldn’t let him look back to say goodbye. “I love him loving me, and at that moment where she drags him away I realize finally I can’t get them back into my orbit anymore,” Grant says of Jonathan.

Jonathan had all of New York captivated, first with his trial and then with his police chase, and that kind of attention from strangers can be a “comfort when he’s in jail,” Grant admits. But it won’t be enough. “He’s been a star of school, of university, of medical college, of medical research, he saves lives. It’s going to be hard for him to just be the star of prison, like the Phoenix Buchanan character I played in ‘Paddington 2.'”