Theodore "Ted" Crawford (Anthony Hopkins), a wealthy and talented structural engineer, discovers his wife Jennifer (Embeth Davidtz) is having an affair with police detective Rob Nunally (Billy Burke). Crawford proceeds to shoot his wife, seriously wounding her and he immediately confesses the crime to Nunally on the scene. However, at his arraignment, Crawford retracts his confession.
He then engages in a battle of wits with rising star deputy district attorney William "Willy" Beachum (Ryan Gosling), who considers this an open-and-shut matter and agrees to go to trial. Beachum is busy making preparations for his transition from criminal law to corporate attorney for Wooton & Simms, a well-known firm, and begins a romantic relationship with his future boss, Nikki Gardner (Rosamund Pike).
At the trial, Crawford acts as his own attorney, which serves as a key vehicle for the plot of the movie - matching up against a star prosecutor as a supposedly untrained litigant. Crawford reveals that the arresting officer (Nunally) was having an affair with his wife and was also present during his interrogation. His confession is ruled to be inadmissible as evidence, as it was fruit of the poisonous tree. Beachum discovers that Crawford's handgun was not used to shoot his wife, because it had never been fired and did not match the shell casings at the murder scene. Since the house was under surveillance the entire time from the shooting to Crawford's arrest, the police are baffled.
While the next hearing is imminent, Beechum is faced with absolutely no evidence against Crawford. Nunally in his intense desire for revenge, offers to plant false evidence through his contact at the evidence room. Beechum, however, being a young and as yet unspoiled lawyer refuses even to consider it. Nunally still goes on to do the dirty plant. Just before the trial, Beechum plots to trick Crawford with the help of his secretary, but at the last moment decides against it. With no new evidence to present to the jury, Beachum is forced to concede the trial and Crawford is acquitted. The disgraced Nunally commits suicide with his own gun outside the courtroom.
Beacham's future with the prestigious firm is in tatters. With the case closed, he obsessively continues to search for evidence. He repeatedly visits the comatose Jennifer in the hospital, hoping she will wake up. But at Crawford's request, a restraining order is issued, forbidding Beachum to visit the patient. Realizing that Crawford's plan is to dispose off the only eyewitness to the crime, Beachum goes to great lengths to get a court order to keep Jennifer on life support. Nikki refuses to help him and they end their relationship. Beachum arrives too late and Crawford orders the hospital staff to take Jennifer off life support, allowing her to die.
A mix-up of cellphones leads Beachum to realize that both Nunally and Crawford used similar guns. He figures out that before the crime, Crawford switched his gun with Nunally's identical Glock 21 in a hotel room where Jennifer and Nunally secretly met. Crawford shot his wife with Nunally's gun, whereupon the detective arrived on the scene carrying Crawford's gun. While Nunally lingered over Jennifer, trying to revive her, Crawford reloaded Nunally's gun and placed it back where Nunally had left it, while at the same time taking back his original gun. Distracted by the sight of Jennifer's body, Nunally did not notice the guns being switched back. When Crawford appears back in the room brandishing his own gun, Nunally tackles and beats him up before Crawford is arrested, at which point Nunally unwittingly holsters his own gun, the murder weapon, and lets Crawford's unused one to be taken as evidence.
Beachum confronts Crawford with his new evidence. Since she died, the bullet lodged in Jennifer's head can now be retrieved and matched with Nunally's gun. Beachum tricks Crawford into confessing, knowing that Crawford thinks he is protected under the double jeopardy clause. However, Beachum reveals that by allowing his wife to die, Crawford can now be prosecuted for murder, having previously been tried merely for attempted murder. If he had not pulled Jennifer off life support, he would have been protected by the double jeopardy clause - and as per the doctors, Jennifer could have died anyway. Crawford is arrested by the waiting police.
The film ends with a new trial about to begin. This time, the defendant is surrounded by attorneys.