But the prosecution painted a picture of a sexual sadist obsessed with beheadings who murdered her as part of a sexual fantasy.

Madsen, who has previously admitted dismembering Wall’s body and throwing her remains overboard, told the Copenhagen district court on the first day of his trial that the air pressure suddenly dropped in the engine room, where the 30-year-old freelance reporter was located while he was up on deck.

Pleading not guilty to premeditated murder, he admitted he had lied to investigators and changed his account of what actually happened to Wall several times.

“I wanted to spare her family and the world the details . . . about what actually happened when she died, because it is gruesome.”

He said a vacuum effect meant he was unable to open the hatch to get in to Wall, who was screaming for help.

“I try to explain to Kim through the hatch how to stop the necessary engines, for 5 to 15 minutes I try to get in to her,” Madsen said.

“When I finally manage to open the hatch, a warm cloud hits my face. I find her lifeless on the floor, and I squat next to her and try to wake her up, slapping her cheeks.”

He said he sailed around for a few hours, contemplating suicide, and then slept next to Wall’s body for two hours.

Cutting her up was not a big deal, as he already knew how to amputate limbs “to save lives.”

“I don’t see how that mattered at that time, as she was dead,” Madsen said with a small grin.

“I tried first with an arm, and that went very fast. . . . It went very fast, and I got her out of the submarine.”

Wall’s chopped up body parts, weighed down in plastic bags with metal objects, were later recovered from waters off Copenhagen.

Wall was reported missing by her boyfriend after she failed to return home from her trip on the 60-foot (18-meter) vessel last Aug. 10.

That evening, the couple were having a going-away party ahead of their planned move to China a few days later.

But Madsen, an eccentric semi-celebrity in Denmark who dreamed of developing private space travel and whom Wall had been trying to interview, contacted her and invited her out to the sub.

On a large screen in the courtroom, the prosecutor showed a series of text messages Wall sent her boyfriend from inside the vessel.

“He has narcissistic and psychopathic traits, and is manipulating, with a severe lack of empathy and remorse,” prosecutor Jakob Buch-Jepsen said.

He said evidence showed Madsen bound Wall by the head, arms and legs before beating her and stabbing her repeatedly in her genital area.

Buch-Jepsen said Madsen then killed her — probably strangling or slitting her throat — and cut her up with a saw, stuffing her torso, head, arms and legs in separate bags weighed down with metal objects, and dumping them in Koge Bay off Copenhagen.

Prosecutors also introduced as evidence a hard drive seized in his workshop containing fetish films, in which women were tortured, decapitated and burned alive.

Seven texts “about impalement of women, mostly in the genitals” were also found.

Madsen has said the hard drive was not his.

Investigators never found Wall’s or Madsen’s phones, but were able to recreate some of the messages on them.

On the morning of Aug. 10, Madsen “Googled ‘beheaded girl agony,’ which leads to a video of an unidentified young woman who is slowly having her throat cut,” the prosecutor said.

On July 26, he also Googled “female beheading” and watched the videos.

Asked why he watched the videos, Madsen said: “It is not of a sexual nature. This is about strong emotions. I watch these videos to cry and to feel emotions.”

Madsen’s defense lawyer said the prosecution’s case didn’t hold up.

“If these statements as presented by the prosecutor can be proven, it would be very incriminating for my client. However there is not enough proof,” Hald Engmark told the court.

The prosecution has said it will seek a life sentence, which in Denmark averages around 16 years. A verdict is expected on April 25.