A man who is pleading insanity in the slayings of seven co-workers testified in the most matter-of-fact way Thursday that he thought he was killing Adolf Hitler and his Nazi henchmen as part of a divine mission to save the world from the Holocaust.

Michael McDermott — a hulking, 43-year-old man with a bushy black beard and long, shaggy hair — said that 12 days before the shooting rampage at Edgewater Technology in Wakefield in 2000, the archangel St. Michael appeared and told him how to earn a ticket to heaven.

"The whole idea was to prevent Nazi supremacy," the software engineer said.

"I felt great. For the first time in my life I felt I could achieve what everyone takes for granted — that I could have a soul and go to heaven."

He also told the jury that he had once attempted suicide, that he had been raped as a boy, and that he heard voices in his head.

Prosecutors say McDermott planned the slayings in retaliation for the company's plan to withhold some of his wages to pay $5,600 in back taxes.

Prosecutor Tom O'Reilly asked McDermott if his two decades of experience with Dungeons and Dragons, a fantasy role-playing game, made him a skilled storyteller who could concoct stories.

"It's not so much concocting as having fun, participating in a group fantasy ...," McDermott replied.

McDermott calmly described how he walked through his office, firing his AK-47 rifle and shotgun. He said he had been transported in time to Hitler's Berlin bunker in 1940, and saw Nazis, not colleagues.

"There were two men and a woman in front of me. Both of the men had swastika armbands. I immediately shot both of the men," McDermott said.

He said he shot three more "Nazis" when he heard "Hitler's thoughts" coming from the accounting office.

"The last Nazi was there. I shot and killed him. And Hitler was there. I shot and killed him," he said. "My mission was complete. I knew at this point I had a soul."

He returned to the office reception area, where he was arrested. He told the jury that he died at a Berlin police station from a combination of painkillers and vodka he downed before the shootings.

The testimony came before a courtroom packed with relatives of the victims. Midway through McDermott's explanation of the shootings, a male relative stood up, uttered an obscenity and left. He was followed by nearly a dozen more relatives.

McDermott acknowledged that he bought a book, "Clinical Assessment of Malingering and Deception," which helps detect when someone is faking mental illness, and had downloaded Internet material about faking psychological disorders.

Defense attorney Kevin Reddington walked McDermott through his history of mental problems, trying to show a pattern of hallucinations that culminated in the shootings.

McDermott claimed he was repeatedly harassed by an ex-girlfriend who worked with him at the Maine Yankee nuclear plant. Reddington said an investigation showed that McDermott actually made the phone calls.

McDermott also claimed he was exposed to radiation, which "pretty much killed my thyroid." Reddington, however, said a blood test showed no evidence of radiation exposure.

When Reddington asked McDermott what year this is, he responded: "I have no idea."

Reddington disputed prosecutors' account that McDermott was angry about the tax issue, saying there was at least $50,000 in his retirement account at the time of the shootings and he wasn't having financial difficulties. He said McDermott suffers from mental illnesses including paranoia, schizophrenia and a disorder that makes people think they are dead.

"The voices in my head, I clustered them into different groups," he McDermott said. "The major one I call the chorus. Its job is to tell me what a bad person I am. ... The chorus continuously tells me what a bad person I am, what a waste of space and skin and air I am."

One of the "non-chorus" groups, he said, tells him to steal things.

He also said he had left his job at the nuclear plant because "I had gone crazy." He said he attempted suicide by slashing his wrist.

McDermott also claimed he was raped several times by a neighbor when he was 8, though it was never reported to police.

McDermott said he got a vasectomy after his 1992 marriage.

"Neither my wife nor I wanted children and I had bad genes," he said. "I wouldn't want to pass my craziness to someone else and I had years of exposure to radiation."

The prosecution is expected to resume its questioning of McDermott when the trial reconvenes Friday.