“Straight Outta Compton,” a biopic about pioneering rap group N.W.A. that co-stars New Orleans actor Jason Mitchell, earned an astonishing $56.1 million in its opening weekend.

According to studio estimates Sunday, the gritty “Straight Outta Compton” blasted past box office expectations while the stylish “The Man From U.N.C.L.E.” struggled to find its footing.

Mitchell’s performance as N.W.A. co-founder Eazy-E, aka Eric Wright, is his first leading role. His previous credits include two New Orleans-filmed crime dramas starring Mark Wahlberg: 2012’s “Contraband” and 2013’s “Broken City.”

Director F. Gary Gray’s well-received “Compton” 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 a companion piece — his first new album in 16 years.

Nick Carpou, Universal’s president of domestic distribution, said the studio was “elated” with the results. It had predicted a $25 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.

“We’ve got the best marketers in the business and they understand their audiences,” Carpou said. “The good news here is it attaches to a product that we’re exceedingly proud of.”

According to exit polls, audiences for the R-rated film were evenly divided between genders, 51 percent were under the age of 30, 46 percent were African-American and 23 percent Caucasian.

Meanwhile, Warner Bros. PG-13-rated adaptation of the 1960s television series “The Man From U.N.C.L.E.” debuted in third place, behind “Mission: Impossible — Rogue Nation,” with a sluggish $13.5 million.

“I was hoping for a little higher number, quite frankly,” said Jeff Goldstein, executive vice president of domestic distribution for Warner Bros. The goal had been a modest $15 million. The period spy thriller will have an uphill battle to make up its $80 million production budget.

“(Director) Guy Ritchie made an original and fun movie. Eighty-six percent of our audience was over 25 and 39 percent are over 50,” he said. “Older audiences, we all know, don’t rush out opening weekend.”

“The Man From U.N.C.L.E.” stars Henry Cavill and Armie Hammer as a pair of American and Russian agents in the fashionable Cold War-era film.

Goldstein noted that they weren’t able to attract a significant younger audience, who are likely not familiar with the source material. The 7 percent who did turn out gave the film a favorable A- CinemaScore, and Goldstein hopes that word-of-mouth will spread in the coming weeks.

Fox’s “Fantastic Four” plummeted to $8 million to take the fourth place spot, while “The Gift” took fifth with $6.5 million.

But it’s Universal’s weekend to celebrate once more in what has become a banner year for the studio. Universal crossed the $2 billion mark domestically on Saturday — four months ahead of previous record-holder Warner Bros.

“Straight Outta Compton” is Universal’s 6th film to open over $50 million in 2015 and broke the August record for an R-rated opening.

“If you were to create a blueprint for how to perfectly execute a box office year, they’ve done it,” said Dergarabedian.

Estimated ticket sales for Friday through Sunday at U.S. and Canadian theaters, according to Rentrak. Final domestic figures will be released Monday.

1. “Straight Outta Compton,” $56.1 million.

2. “Mission: Impossible — Rogue Nation,” $17 million.

3. “The Man From U.N.C.L.E.,” $13.5 million.

4. “Fantastic Four,” $8 million.

5. “The Gift,” $6.5 million.

6. “Ant-Man,” $5.5 million.

7. “Vacation,” $5.3 million.

8. “Minions,” $5.2 million.

9. “Ricki and the Flash,” $4.6 million.

10. “Trainwreck,” $3.8 million.