LOS ANGELES — Sandra Bullock and Melissa McCarthy brought “The Heat” against Channing Tatum and Jamie Foxx at the box office.

The Fox action-comedy starring the funny ladies as mismatched detectives earned $40 million in second place in its opening weekend, topping the $25.7 million debut haul of Sony’s “White House Down,” according to studio estimates Sunday.

The Disney-Pixar animated prequel “Monsters University” remained box-office valedictorian in its second weekend, earning $46.1 million in first place.

As for “The Heat,” employing two female leads to buck the male-dominated buddy-cop formula paid off in ticket sales.

“I think the fact that we have a female-centric movie standing out in a forest of giant tent-pole movies is phenomenal,” said Chris Aronson, Fox’s president of domestic distribution. “Audiences really responded. We positioned this to be a female event movie, and we got the opening that we were hoping for this weekend.”

“White House Down,” which features Tatum as a wannabe Secret Service agent and Foxx as the President of the United States of America, was inaugurated below expectations in fourth place.

“It turned out to be a very competitive weekend,” said Rory Bruer, Sony’s president of worldwide distribution.

Meanwhile, Paramount’s globe-trotting zombie thriller “World War Z” starring Brad Pitt took another bite out of the box office in its second weekend with $29.8 million.

“I think the variety of films is what brought people out to the movie theaters,” said Paul Dergarabedian, an analyst for box-office tracker Hollywood.com.