The Danish submarine builder accused of murdering a journalist flashed a sick smile Thursday as he explained chopping up the Swede’s body and tossing her parts into the ocean — as he blamed her death on toxic fumes aboard his DIY vessel.

Peter Madsen said he slept next to Kim Wall’s lifeless body for two hours and contemplated suicide before deciding what to do next.

“I don’t see how that mattered at that time, as she was dead,” Madsen said with a small grin, when asked why he opted to dismember Wall.

Madsen said he already knew how to amputate limbs “to save lives” — so cutting her up was no problem.

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

Madsen gave the unnerving testimony on the first day of his trial in Copenhagen district court.

Wall’s body parts were later discovered in the waters off Copenhagen, stuffed in plastic bags weighted down with metal objects — 11 days after the 30-year-old freelancer interviewed the eccentric inventor for a story.

Madsen previously admitted dismembering Wall but denied killing her, giving conflicting accounts of the circumstances surrounding her death last August.

The 47-year-old initially told authorities he dropped Wall off on a Copenhagen island — but then changed his tune to claim a heavy hatch on the sub fell on her head. He also suggested that carbon monoxide poisoning was to blame.

On Thursday, Madsen said Wall died when toxic fumes filled the 60-foot vessel, UC3 Nautilus, while he was on deck.

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

He also said he wanted to “stick to my explanation [of an accident] until your evidence means that I have to tell how she died.”

A vacuum effect prevented Madsen from opening the hatch to rescue Wall, who was screaming for help, Madsen said.

“I try to explain to Kim through the hatch how to stop the necessary engines, for five to 15 minutes I try to get in to her,” he 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.”

Wall was reported missing by her boyfriend, Danish designer Ole Stobbe, August 10. The two had plans to move to China a few days later.

She eerily texted Stobbe just after meeting Madsen, who invited her onto his homemade submarine.

“I’m still alive btw,” she wrote. “But going down now!”

She added, “I love you!!!!!!”

A minute later, she texted, “He brought coffee and cookies tho.”

Wall’s cause of death has not been determined. But evidence showed she suffered multiple stab wounds all over her body, including to the genital area.

Prosecutors offered a disturbing portrait of Madsen, saying he was a “perverted polymorph and highly sexually deviant.”

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

Madsen is charged with murder, dismemberment and aggravated sexual assault.

He faces a life sentence, which in Denmark amounts to about 16 years.

The 12-day trial is expected to run until April 25.

With Post wires