The boys from Compton smashed opening weekend expectations, while the stylish “The Man From U.N.C.L.E.” struggled to find its footing.

“Straight Outta Compton,” Universal’s N.W.A. biopic, earned an astonishing $56.1 million in its debut, according to studio estimates Sunday.

Director F. Gary Gray’s well-received film charts the formation and rise of the influential rap group. It cost just $29 million to produce.

N.W.A. members Dr. Dre and Ice Cube served as producers on the film, which has Ice Cube’s real son, O’Shea Jackson Jr., playing his father. Dr. Dre also released the companion piece “Compton” — his first new album in 16 years.

Nick Carpou, Universal’s president of domestic distribution, said they were “elated” with the results. Universal had previously predicted a very conservative $25 million to $30 million opening.

“It really struck a chord with audiences. It’s a story that is resonating right now,” said Paul Dergarabedian, Rentrak’s senior media analyst. “It was one of those records that was an important work and a very important expression of a particular viewpoint. To this day, that album has so much power.”

Beyond the fandom around N.W.A. and the timeliness of the themes, Universal also launched a clever marketing campaign around the film, “Straight Outta Somewhere,” which allows social media users to insert photos in the iconic “Straight Outta Compton” album cover and write in a hometown of their choosing.

There have been over 5.4 million downloads to date and it trended No. 1 across Facebook, Twitter and Instagram for two days in a row.