M. William Phelps needed to cozy up with a serial killer.

He required a monstrous human who had murdered brutally, showed no remorse and understood vicious mind-sets to play an integral role on “Dark Minds,” a reality show that Phelps had created for the cable network Investigation Discovery. The program centered on unsolved serial killings, and Phelps hoped that the assistance of an incarcerated serial killer would provide valuable insights.

He had no idea how much that decision would change him.

As outlined in Phelps’ book “Dangerous Ground: My Friendship With a Serial Killer” (Kensington, out Tuesday), the killer in question is Keith “Happy Face” Jesperson — the nickname derives from a smile he scribbled onto a letter to the Oregonean newspaper, while he was still actively killing. A 6-foot-7 truck driver (an ideally nomadic occupation for a serial killer, it turns out), he used his hands to murder eight women across the country from 1990 to 1995.

For six years, Phelps communicated with Jesperson on a regular basis, accruing around 100 e-mails and 7,000 pages of handwritten letters, and logging hundreds of phone hours.

Phelps wrote the book as a means of figuring out the weird relationship he maintained with Jesperson, now 62.

As Phelps told The Post, “I’ve written 33 true-crime books. I interviewed dozens of killers and several serial killers.” He thought he was impervious to even the most cunningly deranged man. “But this guy? He got inside my head.”

On “Dark Minds” the killer was known as Raven, so as not to bring glory to a man whose chosen method of execution involved a particularly gruesome coup de grâce: jamming his fist down a victim’s throat to make sure she was dead.

Jesperson, whose association with “Dark Minds” is revealed here for the first time, is serving three consecutive life sentences in Oregon State Penitentiary.

Friends had warned Phelps, now 50, against letting the killer into his life or under his skin. John Kelly, a well-known profiler of serial killers, told him, “Phelps, you’re a tough guy . . . But when you invite the devil inside your house, you better be ready to dine with him.”

Kelly’s advice was spot-on. Casual conversations about heinous acts — like the time Jesperson forced a freshly purchased Burger King Whopper into the mouth of a dead girl and laughed about her inability to enjoy it — warped Phelps’ thinking to the point that he could barely sleep, and he wound up in a hospital with stress-related digestive issues.

“The impact was [the] slow annihilation of my soul. [Jesperson’s] total lack of compassion while describing awful acts stripped me of being a peaceful guy who went to mass five days a week,” said Phelps, who began seeing a psychotherapist in lieu of a priest.

One of the worst things Jesperson told him: In 1995, shortly before he was apprehended, the killer needed to dispose of the remains of Angela Subrize, a 21-year-old hitchhiker he had met in Spokane, Wash. So he strapped the woman beneath his big rig — her body disintegrated against the hot asphalt as he drove.

“I asked if she was alive or dead [when he did that]. Jesperson chuckled, and sarcastically asked, ‘What kind of person do you think I am? I think she was dead,’ ” Phelps recalled. “I kept imaging her being alive and that tore me apart.”

Images of the atrocity popped into his mind at the most inopportune times. “I would be watching a volleyball game that my then-12-year-old daughter was playing in,” said Phelps. “Then — bang! — I would [imagine Subrize].”

In terms of what made Jesperson kill, Phelps categorizes him as a born psychopath who was abused as a boy, weathered a difficult marriage (he fathered two children before being dumped by his wife for spending time with prostitutes), became involved with unsavory people and lashed out the only way he knew how.

Jesperson’s cross-wired brain and the circumstances he encountered were simultaneously combustible and numbing.

“I searched for a bit of humanity in this monster. Toward the end of our conversations I saw a sparkle of it,” said Phelps, who, despite it all, remains in touch with Jesperson and hopes to work with him on another project.

“He told me about playing with his pre-school[-age] son in the late 1980s, a year or two before the killings began,” Phelps recalled. As the boy created structures with building blocks, Jesperson would knock them down. He told Phelps it ”[felt] good to see his boy frustrated. Then [Jesperson] said he did not know why he felt that way.

“I didn’t think he could experience sympathy or empathy like a healthy human being . . . and I sensed for a split second that he actually felt something. Then, an instant later, he turned it off and returned to being the psychopath that he is.”