In October 2009, medical researcher Dr. Alice Krippin (Emma Thompson) created a genetically-engineered variant of the measles virus meant as a cure for cancer. After a brief period of successful clinical trials, the virus mutated into a lethal strain that killed 5.4 billion people world-wide. Of those who survived, approximately 558 million devolved into feral and aggressive creatures referred to as "Darkseekers", acquiring heightened agility and strength, along with animalistic cunning, but developed acute photosensitivity (exposure to sunlight causes them severe pain, making Darksiders primarily nocturnal hunters) and lost all human capacity for reason or pity, who then proceeded to hunt down and kill the remaining 12 million humans who were immune to both the virus's lethal and mutagenic effects.
In September 2012, military virologist Lieutenant Colonel Robert Neville (Will Smith) is the last human in New York City, and potentially the last human on Earth. During the outbreak, Robert lost his wife Zoe (Salli Richardson) and daughter Marley (Willow Smith) in a helicopter accident during a chaotic quarantine of Manhattan. Robert's daily routine includes experimenting on infected rats to find a cure for the virus, trying to isolate the gene in his blood that makes him immune, and trips through a decaying Manhattan to collect food and medical supplies or hunt for deer that have wandered into the city from other regions. Lions and possibly other animals have escaped from the Central Park Zoo and are thriving as wild animals seem unaffected by the virus. He keeps vigil each day for a response to his recorded AM radio broadcasts, which instruct any survivors to meet him at midday at the South Street Seaport, where he carefully sits on a bench and waits every day for 30 minutes. Neville's isolation is broken only by the companionship of his pet German Shepard Sam and interaction with mannequins he has set up as patrons of a video store.
He lives in his Washington Square Park townhouse where he settled with his family. During the outbreak, using knowledge from the Darkseekers' habits, he has shielded it with UV projectors and iron shutters inside the windows. He has also set up several generators in the house to provide electricity. He also always returns home before night so the Darkseekers cannot locate his home. He also has a UV-light mounted pick-up truck with safety bumpers.
One day, he is hunting deer with Sam, who chases a deer to an abandoned dark building. He finds the deer dead and discovers the dog hiding and realizes the building is full of infected Darkseekers, and then flees with Sam. To test a treatment, Robert sets a snare trap that uses the scent of blood to capture an infected woman. As he is inspecting the captured woman, a male Darkseeker briefly emerges from the building, screaming in agony as he exposes himself to sunlight; Neville assumes this is due to increased hunger and notes that the loss of all human characteristics in the Darkseekers is complete. In his laboratory in the basement, Neville tries the new serum on the infected woman, seemingly without success.
The next day, he finds one of his mannequins moved on to the street in front of Grand Central Terminal. Robert is unfortunately caught in a snare trap and passes out. He regains consciousness at dusk and frees himself, but a pack of infected dogs attack Robert and Sam. During the fight, one of the infected dogs bites Sam. Domestic animals or animals adapted for a human setting seem to be infected and suffer just like humans as dogs and urban rats can be infected. Robert brings Sam home and attempts to save the dog by injecting a strain of his serum, but it is too late. Sam starts to mutate, forcing Robert to strangle her to death.
Overwhelmed by grief and rage, Robert attacks a group of Darkseekers in the Seaport the following night with his third generation Ford Expedition equipped with UV lights, seemingly as a suicidal last stand. He kills many, but they overwhelm and nearly kill him before he is rescued by a pair of immune humans, a woman named Anna (Alice Braga) and a boy named Ethan (Charlie Tahan), who followed his radio broadcasts from Maryland. Anna and Ethan take Robert back to his home. Anna explains that they are making their way to a survivors' camp in Bethel, Vermont. Robert does not believe such a camp exists and expresses doubt when Anna says God told her about it.
The following night, an alpha male leads an infected mob in an attack on Robert's house. Anna, who was unaware of Robert's precautions in covering his scent outside the house, had inadvertently allowed the Darkseekers to follow their trail. As the Darkseekers charge the house, Robert stops the first wave with UV light projectors, which others destroy. Robert also destroys the second wave with mines planted in the yard, but he finds himself defenseless against the third wave. As Robert tries to find Anna and Ethan, the alpha male and another Darkseeker enter the house, and the alpha male attacks him. As Robert fends off the alpha male, the other Darkseeker rushes upstairs and begins tearing a hole in the roof so others can get in.
After Robert saves Anna and Ethan, they retreat into the laboratory. They seal themselves in a glass-walled room with the infected woman and discover that Neville's treatment is working; the subject looks much more human. The Darkseekers break in and the alpha male begins to throw himself against the glass, cracking it into the shape of a butterfly. Robert then sees Anna's butterfly tattoo and thinks of his daughter Marley, who used to make a butterfly shape with her hands (a brief voiceover of Marley mentioning butterflies plays). Robert then draws a vial of the infected woman's blood and gives it to Anna, before shutting her and Ethan inside a coal chute in the back of the lab. He then detonates an M67 grenade to destroy the attackers at the cost of his own life. Anna and Ethan wake up the next morning to find all of the attackers gone and head towards the survivor colony.
Anna and Ethan arrive at the survivors' colony, where Anna hands over the antidote. Anna later states that the survivors are Robert's legacy, as his fight for a cure became a legend.
The Blu-ray and DVD releases gave the option to view the film with an alternate ending. In this ending, the Alpha male creates a butterfly on the glass wall with his dirty hands, and Robert notices a Butterfly tattoo on the infected woman's arm. They realize there is still hope for them. Robert realises what they want, and after taking a vial of her blood, he removes the serum to make her infected again. He then slowly brings the woman out. The alpha male growls for infecting her again. The Alpha male takes her and leaves with all the Darkseekers (letting him live). The next morning Robert, Anna and Ethan leave New York City and head for the Survivor colony in Vermont.