The movie starts with Tom Ludlow waking up, having been drinking the night before. Working undercover, he meets with Korean gangsters (whom he believes have kidnapped two Korean schoolgirls) in a parking lot, who are looking to buy a machine gun from him. After a vicious beatdown, the Koreans then proceed to steal Tom's car. Tom however planned on this and has the cops locate the vehicle via GPS. Upon arrival at their hideout, Tom storms in and kills the four gangsters and proceeds to cover up what really happened before he rescues the missing children. While the other officers in his unit congratulate him, he is confronted by his former partner, Detective II Terrence Washington (Terry Crews). Washington no longer approves of the corruption and deception and has gone straight, reporting the problems to Captain James Biggs (Hugh Laurie), of Internal Affairs, who starts an investigation against Ludlow.
Upset at Washington for "snitching", Ludlow follows him to a convenience store to confront him. However, Washington is killed by two gangbangers in the store in an apparent robbery, with Ludlow present. Though Ludlow is innocent, the circumstances can heavily implicate him in the murder, which was also known as "wrong place, wrong time". There was a surveillance tape from the store that clearly identifies Ludlow; Wander confiscates the tape in an attempt to protect Ludlow. The DNA of two criminals known as Fremont and Coates is found at the scene, as well as cash and drugs in Washington's possession. It is assumed that Washington himself was corrupt, despite his seemingly changed attitude, and that he had been stealing drugs from the department's evidence room and selling them to Fremont and Coates. Ludlow teams up with Detective I Paul "Disco" Diskant (Chris Evans), who has been assigned to the case to join him in his personal investigation. Their search for the two involves some tough interrogation of other criminals including Winston (Cedric the Entertainer), which eventually leads them to a house in the hills where they discover the bodies of the real Fremont and Coates buried in shallow grave. The condition of the bodies makes it apparent that they were killed well before Washington's murder.
Ludlow and Disco, assisted by Winston, go undercover as dirty cops who are willing to take over Washington's role of stealing and selling drugs. Winston sets up a meeting with the two criminals (Cle Shaheed Sloan and Common) who are posing as Fremont and Coates, and they are revealed to be the two gangbaners who killed Washington . The meeting goes bad when the two criminals recognize Ludlow from the store where Washington was killed before Disco recognizes them. Disco attempts to pull out his weapon but is shot in the throat by Coates, who then attempts to persuade Winston to kill Ludlow. Winston refuses and Fremont kills him. Ludlow manages to kill both Fremont and Coates before he is forced to watch Disco die. Ludlow escapes back to his girlfriend's house where a news report reveals the criminals Ludlow killed were two ex-undercover deputy sheriffs who had lost objectivity (mentioned as two undercover deputy sheriffs).
Shortly afterward, Ludlow is taken from his girlfriend's house by Detective Cosmo Santos (Amaury Nolasco) and Detective Dante Demille (John Corbett), two fellow officers from his unit who are supposedly sent from Wander to protect Ludlow again. However, in the car, they admit that it was they who planted Fremont and Coates' DNA, the cash, and the drugs at the scene of Washington's murder, to prevent him from testifying against them in Biggs' investigation. Ludlow figures out that Washington has been giving up dirt on Wander's entire unit, and that he himself has been a pawn in a plan masterminded by Captain Wander to silence Washington. Dante and Santos were the ones stealing drugs from the department's evidence room and selling them to the two criminals who killed Washington. Santos and Demille take Ludlow out to the house where the real Fremont and Coates' bodies were found earlier for execution. However, Ludlow manages to kill both of them. He then heads to Washington's house to take care of the unit supervisor, Sergeant Mike Clady (Jay Mohr). Ludlow had previously obtained the tape from the convenience store and given it to Linda (Naomie Harris), Washington's wife. Clady has stolen the tape of Washingston's murder from his Linda, and is trying to rape her. However, Ludlow manages to rescue Linda and capture Clady, whom he places in the trunk of his car. Linda goes back to packing her things and moving out of her and Washington's house; they had been planning to move since Washington had gone clean. When Ludlow shows up at Wander's house to confront him, using Clady's cell phone to prove that it was Wander who ordered the hits on Washington and himself. Wander reveals that he has incriminating evidence on most people in the department, as well as judges, councilmen, and politicians. With so many people in Wander's pocket, he has been able to quickly move up the department's ranks as well as protect his department from legal prosecution. Wander tries to convince Ludlow that he is his friend and best officer, and tries to bribe him with a large amount of stolen money and incriminating documents hidden in a wall of his home. Ludlow finally kills Wander, ending the corruption.
Captain Biggs and Sergeant Green, who were "investigating" Ludlow, arrive at the scene, and Biggs reveals that they used Ludlow to bring down Wander by opening Ludlow's eyes to the corruption going on within his unit. As he leaves, Biggs tells Ludlow that the department does indeed need men like him; officers who are willing to bend the rules, but are ultimately honest at heart.