J.C. Penney Co. is in a surprising position more than four years after it was almost run aground by a former chief executive: It could be the last department store standing at your local mall.

As rivals retrench, J.C. Penney is adding new merchandise, exclusive partnerships and services to draw shoppers to its more than 1,000 stores. Sears has closed stores amid $9 billion in losses in recent years and Macy's said last month it would shutter 100 in as-yet unidentified locations — an act likely to leave J.C. Penney as the main anchor in some malls.

"When I joined the company, my first thought was, 'Man, we've got a lot of stores to close,' " said Marvin Ellison, who became president in 2014 and CEO last August. "It was the opposite."

Some of J.C. Penney's most profitable locations turned out to be small stores in rural areas where the retailer pays almost no rent; two California stores opening this year will be completely funded by the landlord. Ellison's focus on mall negotiations, coupled with the changes in merchandising, are helping to move the retailer beyond $1 billion in EBITDA — earnings before interest, taxes, depreciation and amortization — this year for the first time since fiscal 2012. Its stock is up nearly 50 percent this year.

Today J.C. Penney has fewer than 10 stores that aren't making money, Ellison said. The Plano, Texas-based company's fiscal second-quarter net loss was smaller than analysts predicted, and it has outlined a path back to profitability even without achieving the $18 billion in sales it last hit in 2009. Comparable-store sales — a key industry metric — rose 2.2 percent last quarter.

"They have a really unique opportunity, given there's a strong employee commitment to service and a customer focus," said Oliver Chen, an analyst at Cowen & Co. "They have to prove it to everybody that their strategy will yield comparable store sales in an environment that's seen lots of volatility."

Ellison, a former Home Depot Inc. executive, succeeded Mike Ullman, who had returned as CEO after Ron Johnson's disastrous run ended in 2013. Ullman had tossed much of Johnson's strategy and stabilized the chain's finances through loans and stock offerings. That set the stage for Ellison to focus on improving customer service, selling more private brands and revamping online operations.

While the turnaround isn't complete — at about $10, its shares are far below a 2007 peak near $86 — the company is strong enough to take advantage as rivals pull back. When a Sears or Macy's closes, J.C. Penney uses direct mail in the ZIP code to convert those customers. "You make sure you invite them in," said Ellison, 51.

If a mall operator has planned well, there can be side benefits when a competitor leaves, Ellison said. Some types of new tenants — like entertainment options and restaurants — will do a better job at driving traffic than the department stores they replaced.

"They're second movers in things, and being second mover can be turned into a strength," Chen said.

The bad news keeps coming at Sears, which recently reported a $395 million loss for its latest quarter. Through April, Sears had closed 18 percent of its stores since 2006, compared with 6 percent for Macy's and just 2 percent for J.C. Penney, according to Green Street Advisors, a real estate research firm.

J.C. Penney has spent a lot of time and energy identifying its customer. With a heavy emphasis on testing first, the retailer plans to focus on beauty, home goods and special sizes to achieve these goals, along with investments in customer service and online capabilities.

"They're putting their eggs in reliable baskets in beauty and home," Cowen's Chen said.

About 70 percent of J.C. Penney's shoppers are women, and the retailer is working to attract a younger, more diverse set of moms. More than half its revenue comes from shoppers who are, on average, 60-year-old women with incomes above the U.S. median. Most of the rest are mothers who average 33 years of age and are more reflective of U.S. cultural demographics.

J.C. Penney is using beauty products to help draw the latter group — technologically savvy women looking for value in both their time and money. The retailer has 5 percent market share in prestige cosmetics, Chief Merchant John Tighe said. That's in large part because of the 574 Sephora stores open inside J.C. Penney locations. There are plans to expand that partnership even to smaller sites.

Ellison wants the retailer to be the go-to destination for women shopping for their homes. The chain is introducing 500 appliance showrooms this year, selling brands like LG and Samsung. The retailer has cleared as much as 4,800 square feet for appliances — items that bring in eight times more in gross profit dollars than the goods they replace, Ellison said.

In all this, stores are a key component. Expanding its home goods and beauty offerings is part of Ellison's efforts to make the stores a draw, a concept the company refers to as "retail-tainment."

That idea "could speak to how the J.C. Penney of the future could be an important destination," Cowen's Chen said.