LOS ANGELES — The 3-D outer space thriller, “Gravity,” continued to rocket past its box office competition over the weekend, eclipsing newcomer “Carrie,” to maintain its tight grip on the U.S. and Canadian box offices.

“Gravity,” starring Sandra Bullock and George Clooney as astronauts stranded in space, grabbed $31 million in ticket sales at North American theaters to hold the top spot for the third consecutive weekend. It had overall ticket sales of more than $170.6 million.

“Captain Phillips,” a Tom Hanks movie based on a real-life pirate attack, was second with $17.3 million in ticket sales.

“Gravity” beat the $17 million made by “Carrie,” which came in third. The remake of the 1976 horror film starring Sissy Spacek stars 16-year-old Chloe Grace Moretz as the shy girl who wreaks havoc on her tormentors by using her telekinetic powers to destroy her high school prom.

“Gravity” has become a word-of-mouth darling in its third week in movie theaters. Made for a relatively modest $100 million for a special effects film, “Gravity” has been boosted by IMAX’s ultra-large screens, which has accounted for $38 million in ticket sales.

Jeffrey Goldstein, Warner Brothers’ executive vice president for domestic distribution, attributed the film’s success to “phenomenal word of mouth,” and to its appeal in 3-D, noting that 82 percent of audiences opted for 3-D showings. Warner Brothers distributed “Gravity.”

“Carrie” is based on based on thriller writer Stephen King’s 1974 novel. That novel was first adapted by Brian De Palma and received Academy Award nominations for Spacek and Piper Laurie, who plays her abusive mother.

The film’s box office failed to match Hollywood’s forecasts of a $22 million opening weekend, according to website Box Office Mojo.

Still, Sony Pictures’ worldwide president of distribution, Rory Bruer, said that the film’s opening was “within the realm of expectations.”

Horror films have had a good year, with Warner Brother’s “The Conjuring” generating $137.3 million in domestic ticket sales and “Mama,” “The Purge” and “Insidious Chapter 2″ with strong sales.

Other new releases didn’t fare as well. “The Escape Plan,” starring aging action film stars Sylvester Stallone and Arnold Schwarzenegger in a prison escape flick, opened with $9.8 million in ticket sales for fifth place.

“The Fifth Estate,” a thriller based on the news-leaking website WikiLeaks, was eighth with $1.7 million in ticket sales. The film, co-produced by superstar director Steven Spielberg’s Dreamworks studio, received mixed reviews from critics and a thumbs-down from WikiLeaks founder Julian Assange who told the New York Times the film is “a reactionary snoozefest that only the U.S. government could love.”

The animated movie “Cloudy with a Chance of Meatballs 2″ took the no. 4 spot this week, with ticket sales of $10.1 million, pushing the Sony-produced film past $93 million in its fourth weekend in movie theaters.

“Gravity” was released by Warner Bros., a unit of Time Warner Inc. Sony Corp’s movie studio released “Captain Phillips,” “Carrie” and “Cloudy 2.” “The Fifth Estate” was released by Walt Disney’s Touchstone label. “Escape Plan. Was released by “Lionsgate.”