Stories about two childhood friends who grow up in a tough neighborhood and take divergent paths, winding up on opposite sides of the law, are the stuff of Hollywood cliché: one need only think of thirties classics like “Manhattan Melodrama” and “Angels With Dirty Faces.” Scott Cooper’s “Black Mass” falls into that category, but being a modern tale, it has a cynical twist—though one of the men is a mobster and the other a lawman, both prove to be corrupt.

The film also differs from most of its predecessors in being based on fact. It’s essentially the story of James “Whitey” Bulger, who ran the Winter Hill gang in South Boston for a couple of decades from the 1970s to 1994, when he went on the lam as authorities were closing in (he was arrested in California in 2011). But Bulger’s career is coupled with that of John Connolly, a hotshot FBI agent who’d been a pal of Jimmy and his brother Billy (now an important state senator) in Southie when they were kids, and enlisted the mobster as a “partner” in bringing down the Beantown chapter of the Mafia, convincing his Bureau colleagues to give Bulger a pass on his crimes in return for the information he passed on to them about his rivals. Over the years Connolly became increasingly protective of Bulger and was ultimately convicted of complicity in his nefarious deeds.

This is a complicated story, and in crafting a screenplay from the book by Dick Lehr and Gerard O’Neill, scripters Mark Mallouk and Jez Butterworth have elided and simplified things considerably. To offer but one example: Bulger was involved with two women during his years in Boston, but one of them—whom he was living with on the West Coast when he was taken into custody—is simply ignored in favor of a generalized portrait of his relationship with the other, Lindsey Cyr (Dakota Johnson), the common-law wife with whom he had a young son (Luke Ryan). The choice is understandable: the boy’s tragic death provides a means of humanizing Whitey, though it also provides an opportunity to show his dark side when he berates Lindsey for suggesting they should pull the plug on the brain-dead child. The same rationale applies to the inclusion of Ma Bulger (Mary Klug): Whitey is shown as an attentive son, happily losing to his mother in gin games, but when she dies, he has to relegate himself to the organ loft of the church at her funeral to avoid embarrassment with the press. (There’s a touch of “White Heat” at work here.)

While such plot elements give a human dimension to Bulger, however, as a whole the script—presented largely as a triptych (the first act dated 1975, the second 1981 and the third 1985, though it proceeds into later territory))–doesn’t flinch from portraying him as a brutal man who kills easily, from Tommy (Scott Anderson), a comrade he disposes of near the start merely for a drunken argument and Brian Halloran (Peter Sarsgaard), a hot-tempered hophead who tries to turn him in to the feds (an attempt Connolly foils), to Deborah Hussey (Juno Temple), a loquacious prostitute he snuffs personally, and John McIntyre (Brad Carter), whose loose mouth led to the interception of a shipment of weapons Bulger intended for the IRA—and to McIntyre’s torture and murder (Connolly had tipped Whitey off about McIntyre).

All of which gives Bulger a complexity that gives Johnny Depp the opportunity finally to act again. Here he jettisons the cartoonish style that he embraced successfully in the “Pirates of the Caribbean” franchise but that doomed “The Lone Ranger” and “Mortdecai,” as well as the passivity that marked his work in the misguided “Transcendence,” to give a performance that’s alternately chilly and fierce, but always compelling. (The heavy makeup is impressive too, even if in some shots from the side it makes Depp look oddly like Christopher Walken.) Joel Edgerton, as Connolly, frankly can’t match him; he portrays the FBI agent who’s drawn into Bulger’s web as a big, hearty, ambitious man who plans to be the puppet master and only gradually realizes that he’s the one being used, but it’s a turn that doesn’t match Depp’s in subtlety—especially in the latter stages when Connolly falls apart—and so the back-and-forth between the two never has the resonance it might have done. Still, it’s a solid turn, as are Benedict Cumberbatch’s refined, reticent one as Whitey’s circumspect brother and Sarsgaard’s flamboyant one as Bulger’s would-be accuser.

Among the large supporting cast, Jesse Plemons, Rory Cochrane, and W. Earl Brown stand out as the chief members of Bulger’s crew, whose interviews with law enforcement provide the entree to the flashbacks that reveal Whitey’s past in the film’s three acts. The women fare less well, with Johnson and Julianne Nicholson, as Connolly’s increasingly dubious wife, relegated mostly to the background, though Nicholson has an excellent scene when Whitey casually threatens her; and Temple, in what amounts to an extended cameo, makes the naïve hooker a memorable figure of Whitey’s wrath. Connolly is surrounded by a gaggle of other law enforcement types, among whom Kevin Bacon and Adam Scott stand out as skeptical colleagues, as does David Harbour as a more accommodating one who will assist Connolly in protecting Bulger (like Nicholson, he too has a great moment when he cringes beneath Whitey’s withering threats) and Corey Stoll as the prosecutor who refuses to go along with the coddling of Bulger.

Lesser roles have been filled carefully by director Scott Cooper, who—along with production designer Stefania Cella, art director Jeremy Woodward, set designers Bryan Felty, Karl Martin and Christina Todesco, set decorator Tracey Doyle and costume designer Kasia Walicka Maimone, as well as ace cinematographer Masanobu Takayanagi and editor David Rosenbloom—achieves an almost palpable sense of time and place (just as he did in “Out of the Furnace”). He manages several set-pieces—like the murder of Temple’s Hussey—with a masterly hand, and his careful management of moments of abrupt violence keeps the audience consistently on the edge of their seats. Tom Holkenberg contributes a moody score that contributes to the dark atmosphere.

Though very good, “Black Mass” might not be the equal of the greatest gangster pictures. But it has one great element in Depp’s performance, which makes this journey into the world of a vicious crime lord endlessly engrossing and at times positively startling. At least one Oscar nomination seems a foregone conclusion, but others may be in the offing as well.