The film begins in a namless city, with Will Atenton (Daniel Craig) leaving his job as a successful editor in the city in order to spend more time with his wife, Libby (Rachel Weisz), and their two daughters and write a book. At first, they appear to be living the American dream in an idyllic country home they have just moved into. Early in his time at the house, Will notices tension between his neighbor, Anne Patterson (Naomi Watts), and her ex-husband, Jack, who is picking up their teenage daughter. Despite the seemingly perfect house, it soon becomes apparent to Will that something isn't right.
After asking around, Will learns of terrible murders that occurred there five years earlier - a man, named Peter Ward, the previous owner of the house, shot and killed his wife and two daughters. What's more, Will's young daughters claim to begin seeing a man watching them through the windows at night. Will and his wife begin to uncover more information about the murders, despite the local police refusing to help them. Even his neighbor, Anne, who he has talked to on a few occasions, remains strangely distant and won't tell him anything. However, after uncovering some old things in a hidden attic space, they find out that Peter Ward had already been released from custody (as there was no concrete evidence that he actually killed his family) and is living in a half-way house -- and there is a lot of public controversy about it.
When Will's wife also sees the strange man that her daughters had already claimed was watching the house (and the police fail to help), Will, believing it to be Peter Ward, sets off to the half-way house to find him and try and settle things. Will goes to the half-way house and sneaks into what he believes is Ward's room (the number of which he found by looking at the mail pigeon hole marked with his name) and there he finds a picture of his wife and daughters. A man comes in and, extremely angry, Will threatens him to stay away from his family. However, the man is not Peter Ward, but in fact a man named Martin Tishencko (Joe Pingue). Confused, Will returns home.
Further research leads Will to the psychiatric hospital where Peter Ward was initially hospitalized. There, Will is told that he is Peter Ward and that "Will Atenton" is a false identity he invented to mask the trauma of losing his wife and daughters. Although he doesn't believe it, the seams begin to show in what he once thought was reality. More and more evidence crops up, showing that the wife and daughters he believed he had are, rather, just projections in his mind of the family that he supposedly murdered.
It is here that Will begins to slip between realities -- One being his idyllic, yet completely invented, life with his wife and daughters, and the other, in which his house is in ruins and he is the accused murderer of his family, still living in that same house all alone. After his house is deemed by the city as being in an unlivable state, he is evicted - but does not want to leave as whenever he is in this house he returns to his fantasy land with his long dead family. As well as this, he is still unsure which reality is correct.
Anne, Peter's (I mean Will's) neighbor, takes him in, giving him a bath and washing his clothes. She believes his innocence and even her daughter, who had previously had nightmares about the murders, is comfortable with his presence. However, Anne's ex-husband, Jack, somehow hears that Peter is with his ex-wife in her home and comes over to collect his daughter, despite him not yet having custody for a few days. Anne refuses but her daughter obliges in order to avoid any conflict -- yet she runs away as soon as she is out the door. Jack goes after her, and Anne, before following, gives Peter the business card of the psychiatric hospital in which he was previously treated, which she found while washing his clothes.
Peter/Will goes to see his psychiatrist who urges him to come back to treatment, but she does not know if she believes his innocence or not and Peter storms back to his boarded up house. There, he is once again immersed in his fantasy land, but he realizes now that he is Peter Ward, which he tries to convince to his wife. She won't believe it, putting it down to a fever and Peter's high temperature. However, when the girls also get this fever and she finds gaping wounds on the girls' backs she realizes he was telling the truth.
Peter later asks Libby to recall the night of the murders and she tells him everything she can remember - that she heard someone coming up the stairs and the girls, thinking it was their dad, went out to greet him. She also came out, only to find a man with a gun. Peter is jerked from his fantasy by Anne, who is coming to tell him to get out of the house, but before they can leave, Jack and Boyce are there ready to kill Anne and blame the murder on Peter.
We learn that the original murders of Peter's family, were actually carried out by Boyce; he had been hired to kill Anne by Jack after their divorce yet Boyce got the wrong house and killed the Ward family instead. After being shot, Peter's wife had tried to shoot Boyce with a gun he had left on the ground while he was fighting with Peter. Instead, she hit Peter in the head, which explains the absence of any recollection of the events. Both Peter and Anne are knocked unconscious and taken to the basement where Anne is tied up. Jack shoots Boyce for his failure in the previous mission and goes on to light the house on fire with gasoline.
Meanwhile, the projection of Peter's wife is hovering at the edges of the scene and urges Peter to wake up. When he does, he carries Anne out of the fire where she is reconciled with her daughter. Boyce, not quite dead, traps Jack in the fire by pouring gasoline on him before dying himself. Peter rushes back into the burning house where he sees his wife and daughters for the last time and is finally forced to let them go.
The movie ends showing Peter Ward looking through a bookstore window of the book he has just written about his experience -- he was writing a book at the beginning of the film in his fantasy world, but this time the book is under his real name of Peter Ward.