A hostage situation in South Dakota: FBI Agent Art Jeffries (Bruce Willis), as the inside man, protects a 14-year-old boy named James while trying to talk bank robber Edgar Halstrom (Richard Riehle) into surrendering. However, the FBI task force moves in, and in the ensuing firefight both James and the robbers are killed. Jeffries confronts his superior, Hartley, who tells him they both must answer to Washington. An infuriated Jeffries punches Hartley in reply.
A cryptographic code called "Mercury" was created by the National Security Agency and is allegedly so complex that its creators believe no computer on Earth can decipher it. Originally it was created during the Reagan Administration as a test to keep the United States' highest priority secrets under wraps. One day, the NSA receives a message from a nine-year-old autistic savant named Simon Lynch (Miko Hughes), who calls a telephone number written in the code which was secretly published in a puzzle magazine by two of the creators, Dean Crandell (Robert Stanton) and Leo Pedranski (Bodhi Elfman), to see if anyone could break it. Crandell and Pedranski's division chief, Lt. Colonel Nicholas Kudrow (Alec Baldwin) sees the boy's ability to decipher the code as a grave liability. He dispatches an assassin, Peter Burrell (Lindsey Lee Ginter), to murder the boy and his parents, Martin (John Carroll Lynch) and Jenny (Kelley Hazen).
After shooting Martin and Jenny, Burrell searches the house, fails to find Simon, and leaves at the sound of approaching sirens (Martin was able to call 911 before dying). Jeffries, who has been demoted following a diagnosis of delusional paranoia, is sent to investigate what is initially thought to be a murder-suicide. While investigating the scene, Jeffries finds Simon hiding in a cache of his bedroom closet and takes the boy under his wing. Jeffries begins to realize the difficulty of protecting, let alone questioning, Simon because of his impaired social abilities as a result of his autism, but the Chicago PD agree to assign a protection detail to Simon. Burrell tries to kill Simon again at the hospital, but Jeffries stops him. He is then forced to terminate an assassin named Shayes (Peter Stormare) on the Chicago 'L' train. The situation is further complicated by the fact that nobody at the FBI believes Simon is in any danger, and Jeffries is soon framed by the NSA as a kidnapper, with only his best friend and fellow agent Tommy Jordan (Chi McBride) aware that he did not commit the crime, since Jordan had been in contact with Jeffries when the incident began. Jeffries borrows Jordan's car (which Jordan later reports stolen to conceal his involvement) and takes Simon back to his house. Simon again calls the telephone number written in the code, and, after realizing that Simon is talking to Crandell and Pedranski, arrangements are made for a meeting at the Wrigley Building. The next morning, he meets a woman named Stacey Siebring (Kim Dickens) in a coffee shop and asks her to watch Simon for him.
Jeffries meets Crandell and they talk as they walk on a busy sidewalk. As Crandell tells Jeffries about the code and Kudrow, Burrell shoots him from behind and escapes from Jeffries. Jeffries goes back to the coffee shop, but Simon and Stacey are gone. He goes outside and spots them coming across the street. Stacey says she and Simon have become friends and Simon agrees. Jeffries and Simon then abruptly leave Stacey. Later in the middle of the night, Jeffries and Simon go to Stacey's house, asking for a place to stay. Stacey reluctantly agrees and tells Jeffries that she was going on a business trip to Des Moines to make the rent the next morning.
Meanwhile, Pedranski turns to Jeffries for help, but shortly after, he too is murdered by Burrell. However, he has managed to leave a letter (on carbon paper) detailing Kudrow's crimes, which his girlfriend, NSA analyst Emily Lang (Carrie Preston) takes to the FBI, and Jordan discreetly arranges for her to meet with Jeffries to show them both the carbon paper used to type the letter, which, being covered in Pedranski's fingerprints, is crucial evidence in its own right. After the meeting with Emily, Jeffries tells Stacey to call anybody for an emergency except the police, who were called off at the last minute, and gives her Jordan's number in case of an emergency. While Jeffries introduces himself to Kudrow at his birthday party and demands that Kudrow leave Simon alone, Jordan, under Jeffries' suggestion, arranges for Simon to go into Witness Protection. After the meeting, Jeffries calls Jordan, who explains that the Witness Protection meeting is going to happen, though they are unaware that their conversation is being monitored by Kudrow. When Jeffries returns and finds Stacey and Simon gone, he learns from Jordan that they are fine and will meet them there, just as Jordan is given an order to head to the FBI director's office.
Kudrow tries to have FBI SAC (Special Agent in Charge) Joe Lomax (Kevin Conway) help him stop Jeffries by using his authority and the fact that Jordan arranged the Witness Protection under false pretenses. He plans to have the NSA take over the protection for the meeting location. After Kudrow leaves, Jordan shows the evidence to Lomax and despite his initial doubts, Jordan confirms that the fingerprint markings on it were Pedranski's, now fully validating the evidence against Kudrow. Jeffries, with Jordan and a small FBI task force's help, sets a trap at the meeting spot. During the battle, Jordan protects Stacey, and the FBI team takes on Burrell, who is killed, trying to escape, when the windows blow out, while Jeffries and Kudrow fight on the roof. Simon gives the FBI agent Kudrow's own gun, allowing him to take control as Jordan and the team come in. In a last-ditch effort to get Simon back, Kudrow grabs the screaming boy, is shot by Jeffries, and subsequently falls to his death over the edge of the building.
Jeffries later visits Simon (now living with foster parents) at his school. He embraces Jeffries as a welcome friend, having finally accepted him as a person he trusts.