Robert Neville is the apparent sole survivor of a pandemic whose symptoms resemble vampirism. It is said that the pandemic was caused by a war, and that it was spread by dust storms in the cities and an explosion in the mosquito population. The narrative details Neville's daily life in Los Angeles as he attempts to comprehend, research, and possibly cure the disease, to which he is immune. Neville's past is revealed through flashbacks; the disease claimed his wife and daughter, and he was forced to kill his wife after she seemingly rose from the dead as a vampire and attacked him.
Neville survives by barricading himself by sunset inside his house, further protected by garlic, mirrors, and crucifixes. Swarms of vampires, led by Neville's neighbor, Ben Cortman, regularly surround his house, trying to find ways to get inside. During the day, he scavenges for supplies and searches out the inactive vampires, driving stakes into their hearts to kill them. He finds brief solace in a stray dog that finds its way to his house. Desperate for company, Neville slowly earns the dog's trust with food and brings it into the house. Despite his efforts, the dog proves to be infected and dies a week later.
After bouts of depression and alcoholism, Neville decides to find out the scientific cause of the pandemic. He obtains books and other research materials from a library, and through painstaking research discovers the root of the disease in a strain of bacteria capable of infecting both deceased and living hosts. He also discovers that the vampires are affected by the garlic, mirrors, and crosses because of "hysterical blindness", the result of previous psychological conditioning of the infected. Driven insane by the disease, the infected now react as they believe they should when confronted with these items. Even then, their reaction is constrained to the beliefs of the particular person; for example, a Christian vampire would fear the cross, but a Jewish vampire would not.
Neville also discovers more efficient means of killing the vampires, other than just driving a stake into their hearts. This includes exposing them to direct sunlight (which kills the bacteria) or inflicting deep wounds on their bodies so that the bacteria switch from being anaerobic symbionts to aerobic parasites, rapidly consuming their hosts when exposed to air. He is now killing such large numbers of vampires in his daily forays that his nightly visitors have diminished significantly.
After three years, Neville sees an apparently uninfected woman, Ruth, in broad daylight, and captures her. After some convincing, Ruth tells him her story of how she and her husband survived the pandemic (though her husband was killed two weeks earlier). Neville is puzzled by the fact that she is upset when he speaks of killing vampires; he thinks that if her story of survival was true, she would have become hardened to the act. He attempts to test whether she is a vampire by exposing her to garlic, which causes her to recoil violently. At night Neville is startled awake and finds Ruth fully clothed at the front door of the house. Suspicious, he questions her motives, but relates the trauma of his past, whereupon they comfort each other. Ruth reluctantly allows him to take a blood sample but knocks him unconscious when the sample reveals that she is infected.
When he wakes, Neville discovers a note from Ruth confessing that she is actually infected and that Neville was responsible for her husband's death. Ruth admits that she was sent to spy on him. The infected have slowly overcome their disease until they can spend short periods of time in sunlight, and are attempting to build a new society. They have developed medication which helps them to overcome the most severe symptoms of the infection. Ruth warns Neville that her people will attempt to capture him, and that he should leave his house and escape to the mountains.
Neville cannot bring himself to leave his house, however, and assumes that he will be captured and treated fairly by the new society. Infected members of the new society eventually attack the house. During the attack, the members of the new society violently dispatch the other feral vampires outside the house, and Neville becomes alarmed at the grim enjoyment they appear to take from this task. Realising that the intention of the attackers may be to kill him rather than to capture him he tries to defend himself with a pistol, leading to one of the infected shooting and badly injuring him.
Neville wakes in a barred cell where he is visited by Ruth, who informs him that she is a ranking member of the new society but, unlike the others, does not resent him. Ruth attempts to present a facade of indifference to Neville, but is unable to maintain it during her discussion with him. After discussing the effects of Neville's vampire killing activities on the new society, she acknowledges the need for Neville's execution and gives him pills, claiming they will "make it easier". Fatally injured, Neville accepts his fate and asks Ruth not to let this society become heartless. Ruth kisses him and leaves.
Neville goes to his prison window and sees the infected waiting for his execution. He now sees that the infected view him with the same hatred and fear that he once felt for the vampires; he realizes that he, a remnant of old humanity, is now a legend to the new race born of the infection—a monster that walks by day and seeks out vampires to kill. He recognises that their desire to kill him is not something he can condemn. As the pills take effect, he thinks: "[I am] a new superstition entering the unassailable fortress of forever. I am legend."