Five months before Yan's death Yan (Tony Leung Chiu Wai) seeks to uncover the link between Triad boss Sam (Eric Tsang) and the mysterious mainland triad boss Shen (Chen Daoming). Since Sam's ascension to the seat of triad lord was due to Ngai's (Francis Ng) death (see second film), Sam is suspicious of all those who followed him in the past. He tests Yan's loyalty by asking him to smash an ashtray on Shen's follower during a negotiation, resulting in Yan being arrested by Inspector Yeung (Leon Lai Ming). After being released, Shen smashes a bottle of liquor on Yan's head and called truce between his gang and Sam's gang.
At the same time, Yan is prosecuted by the police for violent behavior. His superior Wong (Anthony Wong Chau Sung) manages to persuade the court to allow Yan to go and see a psychologist instead of being sentenced to prison. Thus we are shown how he met Dr. Lee (Kelly Chen) regularly for psychological therapy. The two subsequently begins a romantic relationship.
Later, Sam asks Yan to deliver illegal arms to Shen but he himself and other members of the gang did not turn up. Yan delivers the cargo but Shen's gang discovers it is just empty boxes and both gangs begins firing gunshots at each other. Shen and Yan shoot each other in the battle, but both aim at the limbs. Shen thus discovers that Yan is a cop just as Yeung arrives at the scene. Yeung then tells Yan that Shen is not Shen (but actually an undercover cop from the mainland). Yeung also tells Yan that it was due to Yan leaving the police cadets that he gained top honours, thus revealing that Yeung knew Yan is a cop. The three shake hands and wait for the mayhem to die down before returning to their bases.
Ten months after the events of Infernal Affairs Former Triad mole turned top cop Lau Kin Ming (Andy Lau) has been demoted to administrative duty pending the investigation of his involvement in the death of Yan and Billy (Gordon Lam Ka Tung). In a flashback, we see a version of events that transpired through the lie Lau tells the police; Billy was the mole who wanted to kill Yan and Lau was there to arrest him when he shot Yan in the head, leading to Lau shooting Billy.
After months of investigation, he is transferred back to Internal Affairs. He struggles to whitewash his past and keep his cover, while finding out a fellow Security Division Inspector (Yeung) has ties with Shen, the alleged mainland triad boss who had connections to Sam. He tries to determine whether Yeung is another former mole out to execute anyone who could give him away. A battle of wits develops between Ming and Yeung as each tries to learn the other's secret.
Meanwhile, Ming's sense of identity collapses as he begins to lose track of reality, wrestling with his deep guilt in Yan's murder. He has trouble sleeping and is continuously using sleeping pills and is in the middle of going through a divorce with Mary (Sammi Cheng) due to her knowledge of his secret.
Ming sets up security cameras all over the Security Division floor and Yeung's office in order to spy on him. He also steals and hacks into Dr. Lee's computer and finds Yan's file. He learns about Yan and his psychological trauma soon deteriorates to the point where he begins to think he is Yan. He even makes it his own personal mission to apprehend "Lau Kin Ming" and to catch Yeung on behalf of Inspector Wong. After seeing an incident where he holds out his gun and talking to an imaginary person, Lee brought Ming back to her office and hypnotises him. Under hypnosis Ming reveals to a shocked Lee that he is Sam Hon's mole.
Ming continues to suspect Yeung is related to the mainland Chinese gang and Sam. He breaks into Yeung's office and steal tapes from his safe, using his spy cameras to determine the code. He thinks he hears tapes of Yeung relating information to Sam and he leads his team to the Security Division to arrest Yeung, just as Shen arrives. As Ming plays the tape, a conversation between himself and Sam from the movie theatre scene in Infernal Affairs is played and his second-in-command tries to arrest him instead. Ming suffers a psychotic break, asks for a chance to be a good man, but Yeung declares that "I am a policeman." the same way Yan did. Ming finally breaks and yells out "I am also a policeman!" and fires at Yeung's forehead, killing him. Ming is then shot by Shen who snuck a gun behind his back in case a fight would break out and he falls on the floor. Ming then attempts suicide by shooting himself in the neck, but fails.