LOS ANGELES — It was a surprise photo finish at the weekend box office, with the feel-good drama “Hidden Figures” and “Rogue One: A Star Wars Story” each selling an estimated $22 million in tickets at North American theaters.

Most analysts had expected “Rogue One” (Disney) to easily repeat as the No. 1 multiplex attraction. The “Star Wars” spinoff has now collected about $477.3 million over four weeks. Overseas, it has taken in another $437 million.

But in its first weekend in wide release “Hidden Figures” (20th Century Fox), about unsung black heroines in the NASA space race of the 1960s, was lifted by strong reviews, an aggressive four-month marketing campaign that included a grass-roots appeal to faith audiences, and attention on Hollywood’s annual awards circuit. Fox said “Hidden Figures,” directed by Theodore Melfi and starring Octavia Spencer, Taraji P. Henson and Janelle Monáe, did particularly well in San Francisco, Washington, Chicago and Cleveland.

Produced by Chernin Entertainment and Levantine Films for about $25 million, after accounting for tax credits, “Hidden Figures” received an A-plus grade from ticket buyers in CinemaScore exit polls. The movie was most popular with women (64 percent of the audience) and people over the age of 35 (about 56 percent of attendees).