Todd Mullins and his wife, Julie, started going to a shopping center 15 minutes from their Palm Beach Gardens, Fla., home about a year ago—after they joined a gym inside of it. They work out at the Orangetheory Fitness there three to four times a week, and at least half the time visit a nearby juice shop, restaurant or Trader Joe’s, he says.

“There would be no other reason to go to that mall,” says Mr. Mullins, a senior pastor at a local church.

Mall owners long treated gyms like pool halls, unwanted tenants that attracted lower-rent visitors who were unlikely to shop. Now they’re giving health clubs some of their best real estate.

The reason is twofold. Retailers have closed hundreds of stores across the country amid increasing competition from online shopping, leaving mall owners to grapple with declining foot traffic and rising vacancies. At the same time, fitness centers have boomed and diversified, and a proliferation of smaller, boutique gyms that draw higher-end customers have created more attractive tenants that are easier to accommodate.

The result is that health clubs that were once pariahs at malls are helping transform them into hubs of living, working and playing.

Members lift weights on the fitness floor at the Life Time Athletic gym in Franklin, Tenn. With brick-and-mortar retail struggling and fitness surging, health clubs are taking over the anchor spaces previously held by department stores in shopping malls.PHOTO: JOE BUGLEWICZ FOR THE WALL STREET JOURNAL

“Twenty-five years ago, the best real estate was given to the department stores,” says Sandeep Mathrani, CEO of Chicago-based GGP Inc. “And the department stores sort of prevented you from doing anything but having retail shopping. So today, their sort of slow retraction is giving us the opportunity to reinvent the wheel.”

Mr. Mathrani says gyms are one element in making regional malls as well-rounded as downtown areas were years ago, with a YMCA and small shops as well as department stores. GGP plans to integrate fitness centers into half of its 115 malls in the next decade, he says.

Phillips Edison & Company has gyms in 44% of its more than 340 grocery-anchored shopping centers, according to CEO Jeff Edison. In the mid-1990s, the company had just a few centers with gyms because tenants viewed typical gym-goers as teenage weightlifters more likely to hang out on the curb than to shop, Mr. Edison says.

Westfield has 33 U.S. malls, many with assets greater than $1 billion. More than half of them have some sort of health club, up from about 10% a decade ago.

Many of the new tenants at shopping centers are gyms and specialty fitness studios that in some cases are barely bigger than a Starbucksstore. But owners of regional malls also are welcoming sprawling, full-service health clubs as anchor tenants, sometimes replacing the stores that once excluded them.

Members enter the Life Time Athletic gym in Franklin, Tenn. The company is also opening a 180,000-square-foot health club in Oklahoma City’s Quail Springs Mall.PHOTO: JOE BUGLEWICZ FOR THE WALL STREET JOURNAL

GGP is replacing a Macy’s at Oklahoma City’s Quail Springs Mall with a 180,000-square-foot Life Time health club with indoor and outdoor pools and tennis courts. GGP soon will open the first gym, a Planet Fitness , in Honolulu’s Ala Moana Center, whose 350 stores include Louis Vuitton and a Tesla showroom.

Years ago, health clubs were “on a long list of prohibited uses that included massage parlors, billiards halls and pawnshops,” says Steven Gartner, managing director of retail at CBRE, the commercial real-estate services and investment firm. If gyms were allowed in malls at all, landlords often relegated them to back corners.

The fitness industry brings its own risks. Streaming fitness servicesused remotely are on the rise, and the growth of health clubs is outpacing membership, according to the International Health, Racquet & Sportsclub Association. Many midprice gyms have struggled to compete with boutique studios and bargain chains.

Yet overall, fitness has been booming. More than 57 million people belonged to a health club last year—19.3% of the U.S. population—and memberships have jumped 26% since 2009, according to IHRSA.

Gyms fit into a broader push by mall owners to reinvent themselves as centers of entertainment at a time when so much of apparel sales have moved online. Landlords are adding restaurants, ice-skating rinks, pools and other recreational options to boost sagging foot traffic.

People spend time in the lounge at the Life Time Athletic gym in Franklin, Tenn. PHOTO:JOE BUGLEWICZ FOR THE WALL STREET JOURNAL

There is also evidence that gyms might not be the retail repellent that mall owners long thought. More than 40% of health-club members reported household incomes exceeding $100,000 in 2016, according to IHRSA, compared with 26% of the overall population.

Consumer spending at fitness centers climbed 3.7% in the third quarter over last year, according to Atlanta-based spending-data analysis firm Cardlytics. By comparison, spending on apparel at brick-and-mortar stores rose 0.5%.

And people who work out are more likely than ever to shop afterward because it has become socially acceptable to wear fitness clothing outside the gym, says David Jamieson, chief operating officer at Kimco Realty Corp.

Kimco owns 507 mostly grocery-anchored shopping centers, about one-third of which house health clubs. A 2015 Kimco case study found the arrival of LA Fitness gyms at two shopping centers, one in Connecticut and another in the greater New York metro area, prompted 15% to 20% rent increases for nine new, neighboring tenants, Mr. Jamieson says. Six existing tenants had sales increases of 30% or more in the year after the gym opened, he says.

A recently announced project in Atlanta’s upscale Buckhead neighborhood illustrates fitness’s role in remaking the traditional mall. Life Time is building a 90,000-square-foot health club with a rooftop pool and bistro as part of Simon Property Group ’s ongoing transformation of Phipps Plaza. Life Time also will offer workspace memberships as part of a program called Life Time Work, an outgrowth of the rising number of people who do work at the gym.

Members participate in a yoga class at the Life Time Athletic gym in Franklin, Tenn. PHOTO: JOE BUGLEWICZ FOR THE WALL STREET JOURNAL

Equinox, the New York-based luxury health club chain, will be an anchor tenant in a $125 million expansion of The Shops at Willow Bend, a 1.3-million-square-foot complex in the Dallas suburb of Plano, Texas.

The two-story, 35,000-square-foot Equinox, slated to open in late 2018 next to Neiman Marcus, will feature a roof deck for classes and events, says John Albright, vice president of development for Starwood Retail Partners, the mall’s developer and operator.

The proliferation of boutique fitness studios, which specialize in things like cycling or boot camp and often command $30 or more a class, has made fitness more attractive and easier to fit into retail centers. Nationwide, membership in fitness boutiques grew 74% from 2012 to 2015, compared with 5% for traditional commercial gyms, according to IHRSA.

“We’re like the nice-looking girl at the dance. Everybody wants to dance with us these days,” says Dan Adelstein, vice president of international development for Orangetheory Fitness.

The Boca Raton, Fla.-based chain has opened more than 700 U.S. locations since its 2009 founding. Orangetheory’s classes lead people through a circuit of treadmills, rowing machines and free weights. Classes typically run an hour, eliminating gym-floor wandering and keeping parking-lot traffic moving, Mr. Adelstein says.

People work out during an Orangetheory Fitness class.PHOTO: ORANGETHEORY FITNESS

Orangetheory recently teamed with Hy-Vee, a West Des Moines, Iowa-based chain of more than 245 Midwestern grocery stores, to build studios adjacent to and inside stores. The first joint location opened earlier this month in Shakopee, Minn., outside Minneapolis.

Owners of grocery-anchored shopping centers see fitness as a way to fend off competition from Amazon, whose acquisition of Whole Foodsannounced its push into fresh-food sales.

Christa Pelc says she often jumps on an elliptical machine at Anytime Fitness in Hoffman Estates, Ill., then picks up dinner ingredients at Mariano’s, a natural-foods grocery store next door. “It’s really so convenient,” the 29-year-old real-estate paralegal says. “I’m in love with the place.”

A SoulCycle studio is scheduled to open early next year at Westfield’s UTC outdoor mall in San Diego. It will nestle beside two restaurants that serve organic and locally sourced foods, and a short walk from several cosmetics stores—also hot-sellers.

“We’re thinking of this as an ecosystem,” says David Ruddick, Westfield executive vice president of leasing. “It’s not just a workout.”