Add J.C. Penney Co. to the growing list of American retailers that will shrink to survive a shift away from traditional stores.

The 114-year-old chain, which had avoided mass closings despite years of losses, said it would shut as many as 140 of its roughly 1,000 stores by June. The company said it was also offering a voluntary buyout program to 6,000 of its employees.

Penney on Friday eked out its first annual profit since 2010, but executives said they were closing weaker stores so they could focus their investments on revamping those in stronger markets. Penney said it would identify the locations that are set to close next month, though executives said many were smaller stores in rural locations.

The company joins a parade of traditional chains announcing plans to close locations this year after struggling to draw shoppers during the holiday season as more shopping moves online. Macy's Inc. has plans to close 100 locations and is exploring options for the rest of its real estate, while Sears Holdings Corp. is closing 108 Kmart and 42 Sears stores.

Analysts have said that hundreds of department stores are likely to close, especially in weaker and older malls as they lose business to online rivals such as Amazon.com Inc. as well as off-price retailers like TJX Cos. This week the parent of TJ Maxx and Marshall's said it would open about 1,800 stores -- about a 50% increase from its current base.

Penney Chief Executive Marvin Ellison said the closings will allow Penney to adjust its business to "effectively compete against the growing threat of online retailers." He said the remaining store base gives Penney an advantage since the locations can be used to ship or pick up online orders, minimizing delivery costs. In 2016, about 77% of Penney's online orders touched a physical store.

In an interview, Mr. Ellison acknowledged that smartphones are changing how people shop, giving them greater transparency on pricing and less reason to browse different areas of department stores. But he said the department-store model is "not broken. We just have to adjust."

In 2016, while retail sales rose across the board, online retailers took much of the spoils. During the year, spending rose 11% at online retailers and fell almost 6% at department stores, according to Commerce Department figures.

The closings were necessary, analysts said, even though it will make it harder for Penney to capture business it might have gained from Sears or others that were closing in the same malls or nearby locations. "The company is now making the right moves with its real estate," analysts at Citi wrote in a note to clients.

Shares of Penney fell 9% to $6.25. The stock has now dropped 25% this year, leaving a market cap of less than $2 billion for a business that booked revenue of $12.55 billion last fiscal year but just $1 million of profit.

Mr. Ellison, a former Home Depot Inc. executive, took over the company in August 2015 and has been trying to reduce its reliance on apparel by adding Sephora boutiques inside its stores and more items for the home, such as appliances. The company has been trying to recover ground lost to a failed overhaul by former CEO Ron Johnson, who upended its pricing strategy and offerings in an effort to make the chain more hip.

During the quarter ended Jan. 31, the company's same-store sales fell 0.7%, compared with 4.1% growth in the previous year's period. Penney expects the metric to be down 1% to up 1% for the year.

In all for the fourth quarter, Penney posted a profit of $192 million, or 61 cents a share, compared with a loss of $131 million, or 43 cents, the prior year. Revenue slipped 0.9% to $3.96 billion.

Penney's results cap a week in which chains such as Wal-Mart Stores Inc. and Home Depot Inc. recorded strong sales growth but department store operators including Macy's and Kohl's Corp. reported lower revenue and profits.

Unlike its rivals, Kohl's executive said they had no plans for mass closings at the 1,150-store chain. On Thursday, CEO Kevin Mansell said Kohl's will instead focus on lowering inventories, remodeling locations and shrinking its footprint by relocating some weaker stores into smaller locations.

The dwindling visits to U.S. shopping centers even caught up with Victoria's Secret and Bath & Body Works, two retail stalwarts that previously shrugged off the trend. L Brands Inc., which owns the two brands, warned its profits could fall nearly 25% this year, sending its stock tumbling Thursday.

But another mall giant, Gap Inc., posted higher comparable quarterly sales for the first time in two years. "If you read the headlines today, you'll see the words dead, dying, sick. We are none of those," CEO Art Peck told investors late Thursday. "We are healthy and strong and have a plan and clear direction."

Write to Anne Steele at Anne.Steele@wsj.com