Lights, camera, action!
We open with a monologue by Frank Costello, an Irish gangster whose general life philosophy is to take whatever you want and kill anyone who gets in your way.
So there's that.
In a flashback, Frank meets a little boy named Colin Sullivan and takes him under his wing. He teaches Colin his life philosophy and helps him out with groceries. When Colin grows up, he goes into the police force to become a spy for Frank.
While Colin is becoming a cop, so is another young man named Billy Costigan. But Billy has a family history of crime that makes his superiors, Captain Queenan and Sergeant Dignam, unwilling to make him an official cop. What they will do, though, is make him an undercover agent, and they use his family crime history to get him in with Frank Costello's gang in the Southie neighborhood of Boston. So Billy heads out to see if he can infiltrate Costello's group.
The first thing Billy does to establish his street cred is to get himself arrested for assault. He goes to jail for several months and makes connections with people from the Southie neighborhood. When he gets out, he heads to live with his grandmother in Southie and starts doing drug deals with his cousin Sean. But that all comes to a grinding halt when Costello confronts him and orders him to stop doing drug deals in his neighborhood.
Billy realizes that he needs to up the ante if he's going to get in with Costello. So he beats up a couple of mafia guys in a convenience store to get more respect. Costello confronts him once again and tells him that the mafia dudes will soon come back to the neighborhood with a bunch of guys to kill Billy.
But it turns out that the mafia is Costello's biggest enemy, so he decides to bring Billy under his protection—only after wailing on Billy's broken arm with a boot and interrogating him about whether he's an undercover cop, of course. When it's all said and done, Frank seems convinced enough to let Billy into his gang.
Billy starts off with small jobs at first, but it isn't long before he's accompanying Mr. French, Costello's second-in-command, on actual murders. After a year of this stuff, Billy starts losing his mind with anxiety, and he puts more pressure on Madolyn, the psychologist that Captain Queenan has forced him to see. He tells Madolyn that he needs pills to help him sleep, and he flips out when she won't give them to him.
After Madolyn gives in and hands the pills over, Billy asks her out for coffee. Little does he know that Madolyn's boyfriend is Colin Sullivan, Costello's rat in the police department.
Lost yet? We kinda are.
Soon enough, both Billy and Colin realize that the cops have a rat in Costello's group, and Costello has a rat in the police force. So they get down to trying to find one another out. Eventually, Colin has some police officers run surveillance on Captain Queenan. Queenan leads them to Billy, and Colin calls Frank Costello to tell him where he can find his rat. The thugs show up and find only Queenan, since Billy has escaped out a fire escape. They kill Queenan, making the entire police force...not happy.
After the Queenan murder, Colin Sullivan finds out that Frank Costello is actually a protected FBI informant who's been giving people up to the FBI. Along with Costello's constant threats, this info sends Colin over the edge. Colin ends up betraying Costello, and he kills him during a drug sting. Billy barely escapes from the scene and heads to the police station to get his life back, now that Costello is dead and his job is officially over.
Billy meets with Colin to go over his paperwork. But when Colin leaves the office for a moment, Billy finds evidence proving that Colin is Costello's rat. He takes off, and when Colin returns, he realizes that Billy must have found out about him. So he deletes Billy from the police system and basically erases any trace of him ever being an undercover cop.
Billy later comes into possession of tapes that prove Colin is guilty, and he uses them to blackmail Colin into meeting with him. When Colin shows up, Billy beats him up and starts taking him back to the police station. But Billy gets his head blown off by another dirty cop before he can get back out to the street. Colin finds out that this other cop was also working for Costello, but he shoots the guy dead because he can't have anyone connecting him to everything that has happened.
At the end of the day, Billy is dead, and Colin gets away scot-free.
Well, sort of. His fiancée Madolyn does leave him; she knows that Colin is responsible for Billy's death.
In the movie's final scene, Colin returns home and gets shot through the head by Sergeant Dignam, the only person left in the world who knows about Colin—and about Billy being an undercover cop. Dignam walks away, and the final credits roll.