Hacker Matt Farrell (Justin Long
), not knowing who he is working for, finishes work on a computer program and sends it to Mai Linh (Maggie Q
), who advises her boss and lover, Thomas Gabriel (Timothy Olyphant
), that they can now proceed with their operation. Gabriel's operation begins by killing the hackers he hired. This involves using a virus he has implanted that detonates wired explosives attached to the hackers' computers when they press the delete key, and commencing the initial stages of a computer attack on US government networks.
Meanwhile, a young couple is making out in a car at Rutgers University in New Jersey. New York City Detective John McClane (Bruce Willis
) breaks it up; the girl turns out to be his estranged daughter Lucy (Mary Elizabeth Winstead
). She leaves in a huff, refusing to acknowledge her father's last name but calling herself instead by her mother's maiden name, Gennero. Simultaneously, the FBI command center's computers are momentarily interrupted, leading Deputy Director Bowman (Cliff Curtis
) to order a roundup of all the hackers who could conceivably have been involved. McClane is sent to pick up Farrell in Camden, and his arrival interrupts the hacker just before he performs the operation which would detonate his computer. Gabriel's assassins, who had the apartment under surveillance to confirm Farrell's death, open fire. McClane kills several thugs who enter the apartment. Debris from the shootout sets off the explosion of Farrell's computer, destroying the apartment. McClane and Farrell escape down the fire escape, McClane killing various henchmen on the way and Farrell astonished by McClane's calmness during the ordeal.
As McClane makes it to Washington, D.C. with his charge, Gabriel sabotages the nation's network of traffic signals, rail transport and air traffic control. Chaos on the roads ensues. Gabriel also forces the evacuation of numerous federal buildings with a false anthrax alarm, with some of his men infiltrating a Maryland facility by posing as a hazmat cleanup team to sneak in and kill the guards.
After arriving at the temporary FBI office, Farrell recognizes the pictures of the dead hackers on the wall, but denies knowing who they are. Gabriel broadcasts a message threatening the nation, using spliced video clips of the last twelve presidents, and then sabotages the nation's financial systems.
Farrell and McClane are redirected by the FBI to the Department of Homeland Security so that Farrell can be interrogated. While they are on their way, Gabriel begins downloading a huge quantity of significant data from the Maryland facility onto his own computers. McClane, Farrell, and their FBI escort attempt to contact the police to have a route opened for them, but have their radio communication intercepted by Gabriel and Linh, who direct them to an ambush. McClane suspects their communication has been intercepted, so he tests Linh by asking her about a certain police radio code and when she says they've had to dispatch all units to this type of call, which McClane reveals then is actually the code for naked people, exposing her.
Gabriel gets on the radio and advises McClane he knows everything about him, wipes out his financial portfolio, and offers him a bribe to kill Farrell; McClane refuses. McClane and Farrell attempt to evade the ensuing ambush, but are set upon by a helicopter. McClane and Farrell escape the ambush in a police car, and are chased into a tunnel by the helicopter. Gabriel opens the traffic on both sides of the tunnel, sandwiching our heroes in a massive pileup in the middle. McClane drives straight out of the tunnel and jumps at the last second before launching the car up a toll barrier into the helicopter, killing most of the thugs; the one survivor mistakenly tells Gabriel that their targets have been killed.
McClane and Farrell escape on foot, but as they try to contact the FBI via cell phone, they discover that Gabriel has also sabotaged the telecommunications networks. Gabriel then takes over the nation's television signals, and broadcasts the demolition of the U.S. Capitol building; Bowman and McClane each run into the street for a clear view, and see that the footage was faked. Farrell admits that he recognized some of the dead hackers from their pictures, and that he innocently wrote some code that may be being used in this computer attack, which appears to be a three-stage plan to cripple the United States, beginning with attacks on its transportation and financial infrastructures, which have already been accomplished. The third stage will be to take out the power grid; this cannot be done remotely but requires intervention at the actual physical plants. Farrell confesses that he had always viewed hacking as harmless pranks, but is now horrified by the actual damage and suffering caused; he reconfigures the cell phone to use a different network to allow them to communicate.
McClane and Farrell commandeer an abandoned car. By pretending to be the son of its owner in a medical emergency, Farrell gets the car's OnStar system to remotely start it for them. They set off for the main power station in West Virginia which controls the Eastern seaboard. Farrell, who tends to avoid taking action by citing numerous minor medical conditions and phobias, admits to McClane that he doesn't feel capable of heroism.
Linh and a group of henchmen, disguised as FBI agents, meanwhile, have entered the power station, shot the guards, and taken over the facility. As they commence shutdown procedures, McClane and Farrell arrive. Their presence is detected, and henchmen are dispatched to kill them. McClane and Farrell fight their way to the station's command center, McClane fights Linh, and Farrell manages to abort the shutdown sequence. McClane finally kills Linh by driving a truck into her and down an elevator shaft, where the truck explodes at the bottom. Farrell saves McClane by killing one thug, knocking him from behind down the shaft. Seeing that the shutdown hasn't taken place yet, Gabriel calls Linh's cell phone. McClane answers and tells Gabriel that his plan has been foiled and Linh killed. Enraged, Gabriel redirects all the natural gas in the pipelines to converge on the power station. Farrell notices this on one of the computer screens, and he and McClane take shelter just before the station explodes. Gabriel once again believes the pair to be dead. The destruction of the station causes a massive power blackout over Washington and much of the Eastern seaboard. Lucy McClane is caught in an elevator in the blackout.
Farrell and McClane decide to visit "The Warlock" (Kevin Smith
) in Baltimore, who Farrell describes as an "Internet Jedi." Traffic being a nightmare, McClane chooses to fly the helicopter that Linh and her henchmen had used to arrive at the power station. McClane reveals he had a few flying lessons, but never completed the course; they have a rough landing in Baltimore. Meanwhile, Gabriel and a few select henchmen kill his other remaining computer engineers to eliminate witnesses and, travelling light, set out in a semi-trailer with a mobile computer command center in the back.
The Warlock lives in his mother's basement where he has set up his own "command center" -- an impressive collection of computers running on his own generators, interspersed with geek memorabilia. The Warlock is suspicious of the police, but reluctantly agrees to help. He reveals that Gabriel was formerly a highly-placed FBI computer security director, responsible for building much of the system, who discovered its vulnerabilities to attack. When Gabriel brought these vulnerabilities to the attention of his supervisors, ultimately interrupting a meeting of the Joint Chiefs to do so, he was denounced and publicly humiliated. The Warlock tells Farrell that he has been examining the type of code he was hired to write, and that it is only being used at one facility - the one in Maryland, which is still running and drawing massive power loads. Gabriel is alerted to Warlock's intrusions; he traces the intrusion back to Warlock's basement command center, and commandeers Warlock's computer and web cam to communicate with McClane. He shows McClane images of his daughter in the elevator, and advises that he is going to get her. McClane sets off to find and kill Gabriel; he tells Farrell to stay behind, but Farrell insists on helping him. Under the ruse of a rescue, Lucy is brought to Gabriel at the data facility; a chip off the old block, she fights all the way before being tied up.
McClane and Farrell communicate with Bowman and show him an image of Gabriel. Bowman is dismayed; he tells them that the facility still running, part of the National Security Agency, was designed by Gabriel as a failsafe in the event of an attack on the nation's infrastructure. The initial attack on the FBI had triggered the download to that facility of all the financial data from stock markets, corporations, and government agencies. Gabriel apparently intends to download this information onto mobile hard drives, allowing him to undetectably siphon off billions of dollars.
McClane and Farrell head to the data facility, but Gabriel is alerted to their presence. Farrell realizes that the code he wrote was designed to defeat the security at the last door to the facility's main databanks and, slipping in as McClane distracts Gabriel's men, manages to encrypt all the data that Gabriel has downloaded, making it useless to them without the decryption key which he alone knows. He is subsequently captured by Gabriel's thug and brought to the control center where Lucy is also captive. When he suggests to Lucy that she needs to be less confrontational with their heavily armed adversaries, Lucy tells him he needs to show more bravery and resolve. McClane kills the various thugs sent to stop him, and communicates with Farrell via one of the thugs' walkie-talkies. Gabriel attempts to talk McClane down but is unable to do so. He puts Lucy on the radio, to "talk some sense" into her father, but she aids him by telling him that there are only five bad guys left. The bad guys escape in two vehicles: Gabriel, two thugs, and the captives in an emergency services van, and one thug in a semi-trailer carrying their portable computer control center. McClane jumps onto the back of the semi-truck as it leaves the facility, climbs to the cab, shoots the driver through the door, and gives chase to the remaining bad guys and their captives in the van. In the van, Gabriel orders Farrell to unlock the data, but Farrell refuses, knowing that this is his only bargaining chip and that Gabriel will kill him once he has the data back. Bowman orders an F-35 fighter plane dispatched to intercept the van after McClane contacts him via Warlock's CB radio link.
Gabriel realizes they are being chased. He obtains the go codes for the fighter plane by accessing the military's data banks, and impersonates military commanders to order the pilot to destroy the semi-truck. The F-35 fires various missiles and artillery at the truck, causing McClane to break off his chase and move to a ramp leading to a bridge. The F-35 virtually destroys the truck and a large portion of the ramp. As the truck begins to slide backwards down the destroyed ramp, McClane falls out of the cab and down the back of the ravaged trailer. The plane, now just next to the truck, is about to deliver the coup de grace when it is damaged by a chunk of falling pavement. McClane falls onto the plane's wing. The pilot ejects, and McClane slides down the spiralling plane and jumps onto another section of destroyed ramp, sliding down the ramp as the jet crashes and explodes just behind him.
The van carring the bad guys and captives enters a warehouse. McClane pursues them. Gabriel orders Farrell to enter the code to decrypt the information. Farrell refuses and is shot in the knee by Gabriel. When Gabriel puts the gun to Lucy's head and says he will count to ten before killing her, Farrell gives in despite her pleas to resist, and begins to enter the code. McClane arrives and kills one of the henchmen, but is in turn shot in the shoulder by Gabriel. McClane dives behind a car, his gun on the ground near Farrell. McClane goes for his gun but is grabbed by Gabriel from behind. Standing behind McClane, Gabriel taunts him and tortures him by sticking his gun into the bullet wound in McClane's shoulder. Lucy struggles with the thug holding her, shooting him in the foot before he recovers his grip on her. Gabriel tells McClane that his epitaph will read "Always in the wrong place at the wrong time." McClane replies that it might read "Yippee ki yay, mother-" and pulls the trigger, shooting himself through the shoulder and killing Gabriel. Farrell has grabbed McClane's gun and shoots the other thug.
The FBI arrive and provide medical attention to McClane, Lucy, and Farrell. Farrell and Lucy separately indicate to McClane their romantic interest in each other. Lucy indicates that, for today at least, she's a McClane.