John Murdoch awakens in a hotel bathtub, suffering from amnesia. He receives a phone call from Dr. Daniel Schreber, who urges him to flee the hotel to evade a group of men who are after him. In the room, Murdoch discovers the corpse of a ritualistically murdered woman along with a bloody knife. He flees the scene, just as the group of pale men in trenchcoats (later identified as “the Strangers”) arrive.
Following clues, Murdoch learns his own name and finds out he has a wife named Emma; he is also sought by Police Inspector Frank Bumstead as a suspect in a series of murders committed around the city, though he cannot remember killing anybody. Pursued by the Strangers, Murdoch discovers that he has psychokinesis—which the Strangers also possess, and refer to as “tuning”: the ability to alter reality at will. He manages to use these powers to escape from them.
Murdoch explores the anachronistic city, where nobody seems to realize it is always night. At midnight, he watches as everyone except himself falls asleep as the Strangers physically rearrange the city as well as change people’s identities and memories. Murdoch learns that he came from a coastal town called Shell Beach: a town familiar to everyone, though nobody knows how to get there, and all of his attempts to do so are unsuccessful for varying reasons. Meanwhile, the Strangers inject one of their men, Mr. Hand, with memories intended for Murdoch in an attempt to predict his movements and track him down.
Murdoch is eventually caught by Inspector Bumstead, who acknowledges that Murdoch is most likely innocent, and by then has his own misgivings about the nature of the city. They confront Schreber, who explains that the Strangers are extraterrestrials who use corpses as their hosts. Having a hive mind, the Strangers are experimenting with humans to analyze their individuality in the hopes that some insight might be revealed that will help their race survive.
Schreber reveals that Murdoch is an anomaly who inadvertently awoke when Schreber was in the middle of imprinting his latest identity as a murderer. The three embark to find Shell Beach, but it exists only as a poster on a wall at the edge of the city. Frustrated, Murdoch and Bumstead break through the wall, revealing outer space. The men are confronted by the Strangers, including Mr. Hand, who holds Emma hostage. In the ensuing fight, Bumstead and one of the Strangers fall through the hole into space, revealing the city as a deep space habitat surrounded by a force field.
The Strangers bring Murdoch to their home beneath the city and force Schreber to imprint Murdoch with their collective memory, believing Murdoch to be the culmination of their experiments. Schreber betrays them by instead inserting false memories in Murdoch which artificially reestablish his childhood as years spent training and honing his tuning skills and learning about the Strangers and their machines. Murdoch awakens, fully realizing his skills. He frees himself and battles with the Strangers, defeating their leader Mr. Book in a psychokinetic fight high above the city.
After learning from Schreber that Emma has been re-imprinted and cannot be restored, Murdoch exercises his new-found powers, amplified by the Strangers’ machine, to create an actual Shell Beach by flooding the area within the force field with water and forming mountains and beaches. On his way to Shell Beach, Murdoch encounters a dying Mr. Hand and informs him that they have been searching in the wrong place—the mind—to understand humanity. Murdoch turns the habitat toward the star it had been turned away from, and the city experiences sunlight for the first time.
He opens a door leading out of the city, and steps out to view the sunrise. Beyond him is a pier, where he finds the woman he knew as Emma, now with new memories and a new identity as Anna. Murdoch reintroduces himself as they walk to Shell Beach, beginning their relationship anew.