It is a lesson that Hollywood has learned time and time again, from Steve McQueen’s movies to the “Fast and the Furious” franchise: Quick cars and charismatic celebrities sell tickets.

That combination worked once more this weekend for 20th Century Fox’s racing drama “Ford v Ferrari,” starring Matt Damon and Christian Bale. It opened to an estimated $31 million in domestic ticket sales Friday through Sunday, outpacing expectations. The studio had projected an opening weekend of just below $20 million.

Directed by James Mangold, the movie revisits the golden age of auto racing: Damon and Bale play the car designer Carroll Shelby and the driver Ken Miles working for Ford in the lead-up to a historic 1966 race. The cast also includes Tracy Letts as Henry Ford II and Jon Bernthal as Lee Iacocca.

The movie got a boost from critics going into the weekend — it currently holds a 92 percent fresh rating on Rotten Tomatoes. In his review for The New York Times, A.O. Scott wrote that “‘Ford v Ferrari’ is no masterpiece, but it is — to invoke a currently simmering debate — real cinema, the kind of solid, satisfying, nonpandering movie that can seem endangered nowadays.”