Infernal Affairs begins in the mean streets of Hong Kong. The police and the criminals look to deceptive ways to gain the advantage over their adversaries. Chan Wing-yan is a candidate in the police academy who looks to have a promising future in law enforcement. He is approached by his direct superior, Superintendent Wong, to go undercover into the triad for three years to gather information for the Hong Kong Police Force.
The catch, no one will know but Wong that Chan is secretly a police officer. At the same time, a powerful gang boss, Hon Sam, plants multiple triad members into the Hong Kong Police Force, including the young Lau Kin-ming.
The film then skips to ten years later, Chan is still working undercover and is experiencing great stress from his continuous undercover duty. His boss Wong is sympathetic and promises that they are getting close to taking down Hon Sam. At the same time, Lau quickly rises through the ranks of the police force, and has become instrumental in the team surveilling and investigating Hon Sam.
When the police force is preparing to orchestrate a raid on Hon Sam, Lau is brought into the operation. During the planned raid, Lau is able to determine that Wong is communicating with someone on the inside of Hon Sam’s operation using Morse code. However, Lau is not able to find who was communicating with Wong, which the audience knows is Chan.
Before the raid, Lau alerts Hon Sam, giving the gangster enough time to tell his men to get rid of the drugs.
Because the gangsters were alerted to the police operation, Wong also knows that there is mole in the police force providing information to Hon Sam. Now, Wong and Hon Sam are focused on rooting out the mole in their respective operations.
With both sides aware of moles, Wong becomes concerned about Chan and prepares to pull him out of the undercover operation for fear of his safety. Before he can do so, Wong is caught by Hon Sam’s men who attempt to extract the identity of the mole from him. When the inspector won’t give them the information they need, they throw Wong off the building to his death in front of Chan.
After Wong’s death, Lau retrieves the inspector’s cell phone and contacts Chan. The two men agree to foil a massive drug deal planned by Hon Sam. The plan goes without a hitch and many of Hon Sam’s men are arrested. While trying to make his escape, Hon Sam runs into Lau, who betrays the gangster and murders him.
With the triad broken, Chan surrenders himself to the police department with the hope of a return to a normal life. However, he discovers that Lau is Hon Sam’s mole due to him having a piece of paper that Chan had written on previously. Chan flees the police station. Lau, knowing that he has been discovered, begins deleting Wong’s secure files of Chan, the only evidence that he has been an undercover officer for the last ten years.
Chan eventually contacts Lau and they agree to meet on the same roof that Wong was killed at earlier in the film. Chan is able to get the drop on Lau and disarms him. Lau begs Chan for forgiveness, states that he wants to remain a cop, and that he has seen the error of his ways. Chan puts a gun to Lau’s head, and the audience sees that he desperately wants to shoot the mole in revenge for the death of Wong.
Another inspector arrives on the roof and Chan uses Lau as a shield. Chan attempts to maneuver his way to an elevator, but briefly steps out from behind Lau. The other inspector shoots Chan in the head, and Chan falls dead onto the floor of the elevator. The other inspector tells Lau that he too was working for Hon Sam and that they need to watch out for each other.
The inspector and Lau both enter the elevator with Chan’s body. The elevator doors close and we hear gunshots. When they arrive on the ground floor, the other inspector is dead, and Lau walks out of the elevator by himself, having erased another trace of his past. Lau intends on becoming a true cop and is no longer a mole for anyone.
Several months later, Chan’s psychiatrist discovers records revealing Chan’s identity as an undercover police officer. At Chan’s official police officer funeral, Lau salutes his fellow officer and we see a flashback where the two officers’ paths diverged.