For months, anyone could follow the epic struggle in the mind of Joseph Edward Duncan III -- live, on the Internet.

"It is a battle between me and my demons," Duncan wrote in his Web log on April 24. "I'm afraid, very afraid. If they win then a lot of people will be badly hurt."

Three weeks later the demons won, authorities say.

The toll? Three members of an Idaho family bludgeoned to death. Two children dragged to a remote part of Montana, where both were sexually molested and the 9-year-old boy was murdered.

It is hard to conceive a heart black enough to commit such evil acts. But researchers are beginning to understand how another organ, the brain, can conjure the demons that haunt Duncan and other violent sexual predators.

Many, perhaps most, dangerous sexual predators appear to possess one or more brain abnormalities that predispose them to their extreme criminal behavior. Those defects can be caused by traumatic childhood experiences, genetics or events that happen as a person's brain develops in the womb before birth.

But whatever their source, they might eventually be used as a neurological "mark of Cain," offering both a warning of what a person might be capable of and an opportunity to prevent them from realizing that potential.

Freudians might find the seeds of Duncan's behavior in his youth -- a lonely childhood, a domineering mother, his parents' tumultuous relationship.

An unhappy upbringing certainly increases a boy's chances of growing up to be a violent sexual offender. But if an unhappy childhood were all it took to create a sadistic pedophile, every town in America would live under perpetual Amber Alert.

Long before the carnage at the Groene home in Coeur d'Alene, Idaho, Duncan had unleashed his demons on the world. In 1980, at the age of 17, he earned a 20-year prison sentence for raping and torturing a 14-year-old boy at gunpoint. After his arrest for that crime, he told authorities that he had raped 13 boys by the time he was 16.

And authorities now believe that while free on parole in 1997, Duncan kidnapped, raped and murdered a 10-year-old boy in Southern California.

"His preoccupation with deviant sexual fantasies of one kind or another date back to the age of 12," one therapist wrote after evaluating Duncan in 1982. "Mr. Duncan continues to conform to the statutory definition of a sexual psychopath."

Psychopathy is a personality disorder that afflicts a tiny fraction of the general public but about 25 percent of the prison population. Psychopaths are impulsive and self-centered, with little capacity for guilt, fear or remorse. They take great pleasure in manipulating and exploiting other people to get what they want and tend to live disorganized, nomadic lives on society's fringes.

"Psychopaths do know right from wrong; they can tell you right from wrong. They just don't care," said Kent A. Kiehl, a psychiatrist at the Olin Neuropsychiatry Research Center in Hartford, Conn.

Dennis Rader, the BTK serial killer, was the perfect picture of a psychopath during recent televised court appearances. His emotionless recollection in June of killing 10 people illustrated a complete incapacity for guilt or remorse. And his bizarre attempts to make himself seem human at his sentencing by drawing parallels between himself and his victims ("Dolores Davis -- she loved animals and I worked in animal control") revealed an utter lack of empathy.

Kiehl's research suggests that psychopaths have abnormalities in the paralimbic system, a far-flung network of brain structures associated with emotion and emotional memories.

People with brain damage in one component of the paralimbic system, the orbitofrontral cortex, often behave impulsively and selfishly. When epilepsy causes damage to the anterior temporal lobe -- another element of the system -- the result can be inappropriate sexual behavior, problems maintaining personal relationships and a lack of empathy.

And damage to the amygdala, a part of the paralimbic system related to emotional memory and perception, can render people cold and fearless.

Experiments indicate that psychopaths have decreased brain activity in all of those regions. Now Kiehl and his colleagues want to know why.

"Most likely, as with most disorders, there's multiple pathways," Kiehl said.

For example, abuse or stress during childhood could affect how the paralimbic system develops. Brain damage caused by a head injury might induce psychopathic behavior.

But genes almost certainly play a role. A recent study of 7-year-olds by British researchers found that if one in a pair of twins has psychopathic tendencies -- especially, a callous and unemotional personality -- the other is more likely to share those qualities, as long as the two are identical rather than fraternal.

That suggests a hereditary element, because identical twins are genetically identical; fraternal twins share only half their genes.

Some psychologists believe that psychopathy is not so much a disease as an evolutionary artifact. During the millennia of human history before there were criminal justice systems and written records, they say, a small number of psychopaths could lie, cheat and steal their way to success. As long as these deviants remained a small, marginal element of society, people of good conscience might not notice their habitual transgressions.

In a 1995 paper, the late sociobiologist Linda Mealey argued that evolution created two types of psychopaths. The first is purely genetic, born without the capacity for normal human emotion. No matter what, these individuals will go through life with no regard for society's rules or the consequences of their actions.

The other type of psychopathy is also genetic. But it is only produced in the kind of stressful or chaotic social environment in which following the rules does a person no good.

For example, a child who grew up in an abusive clan might produce high levels of cortisol, a stress hormone. The majority of people might have genes for psychopathic behavior that are turned on only in a cortisol-rich brain. So children who grow up in controlled, nurturing environments become productive and law-abiding citizens. Growing up in chaotic, abusive conditions, on the other hand, can create a monster.

If Duncan ever did have a chance to become a well-balanced individual, he lost it early. Court records indicate that his family moved constantly because of his father's military career. His parents fought incessantly, and he rarely made friends. He was often teased by his peers. By his own admission, Duncan committed his first sexual assault at the age of 12. The victim was a 5-year-old boy.

How could Duncan have developed his deviant sexual attraction at such a young age?

Like psychopathy, pedophilia appears to originate in a number of ways. But just as the various elements of psychopathy all appear to relate to the paralimbic system, the various paths to pedophilia all seem to pass through a particular part of the brain.

Located just above the ears, the temporal lobe is involved in face and object recognition, musical ability, personality and sexual behavior. If epilepsy or some other condition causes damage to the temporal lobe, a person can become sexually attracted to inappropriate stimuli, even inanimate objects.

"They have all kinds of deviant behaviors," said Igor Galynker, a psychiatrist at Beth Israel Medical Center in New York.

Working with several colleagues, Galynker has performed brain scans on 22 pedophiles and found that they had below-normal activity in the temporal lobe. Other studies have found a similar pattern. And medical journals describe rare cases of men who began molesting children when tumors invaded the same part of their brains; when the tumors were removed, their pedophilia subsided.

"There's something different about the brains of pedophiles," said Vernon L. Quinsey, a psychologist at Queen's University in Canada. "But what exactly it is, it's hard to say so far."

The temporal lobe goes through a transformation as a boy's interest in sex develops during puberty. Perhaps the experience of being molested derails or forestalls that transformation in some way, which might explain why about 10 percent of the boys who report being sexually abused as children grow up to become pedophiles themselves.

But Quinsey believes it is more likely that the tendency toward pedophilia arises even before birth. Some researchers have proposed that male homosexuality can result if the mother's immune system attacks her son's cells in utero, disrupting the process that gradually differentiates male from female brains.

"We think that some similar mechanism might also relate to pedophilia," Quinsey said.

That does not make the two conditions the same, however. According to Quinsey's theory, the brains of homosexual men end up with a complete set of functioning components for sexual behavior, albeit a combination of male and female elements.

But in pedophiles, Quinsey believes, the mother's immune system causes a specific defect in one of the components that guides sexual behavior.

Pedophiles appear to have a malfunction in whatever brain circuitry it is that causes men to seek partners in the optimum age group for successful reproduction. Over evolutionary history, that set of subconscious instructions would have directed most men to partners in the Playboy centerfold demographic -- robust and young, but sexually mature.

Quinsey proposes that pedophiles have the part of the apparatus that codes for robustness and youth, but that they lack the requirement for sexual maturity. So they focus their sexual energies on children.

Quinsey's hypothesis is beyond the ability of current science to test. But whatever it is about their brains that attracts pedophiles to children, it is clear they have no choice in the matter, said Fred S. Berlin, founder of the Sexual Disorders Clinic at Johns Hopkins University.

"These are not people choosing simply to experience an alternative state of mind," Berlin said.

That leaves society with a difficult question: how to handle someone who will never be truly "cured" of his deviance?

In his Internet diary, Duncan railed against sex-offender registration laws and complained about police officers checking up on him at his apartment.

"I have no privacy at all. Anyone in the State, Country, even World can find out where I live, what I look like and what I did when I was a kid by typing my name on any Web browser," he wrote in a Feb. 2 entry.

Yet sex-offender laws gave Duncan enough privacy, freedom and anonymity to go to Idaho three months later with rape and murder on his mind.

Even a Washington state law that allows for the indefinite commitment of sex offenders after they have served their prison terms failed to contain Duncan. Before releasing him from prison in 2000, the state considered holding him for treatment under the law. But because Duncan had been convicted of only one offense before going to prison for virtually all of his adult life, there was no way to demonstrate legally that he could not control himself in public -- he had never really had a chance to live there.

"There would appear to be insufficient evidence to indicate that Mr. Duncan meets the criteria for civil commitment," a March 2000 psychological report concluded. "However, concerns about his ability to refrain from sexual violent behavior remain."

Joseph Edward Duncan III's "deviant sexual fantasies . . . date back to the age of 12," a therapist said.Dennis Rader, the BTK serial killer, showed in a Kansas court an incapacity for guilt or remorse during his emotionless recollection of killing 10 people.