NEW YORK — J.C. Penney is joining its department store rivals in pruning its store numbers in an era of online shopping.

Penney said Friday that it will close 130 to 140 stores as well as two distribution centers over the next several months as it tries to improve profitability. The company said that it would also initiate a voluntary early retirement program for about 6,000 eligible employees.

The news came as Penney posted a profit for the fourth quarter, compared to a loss a year ago. But total sales were down slightly, and a key revenue metric declined a bit as well. The company issued a conservative annual forecast, sending shares down 9 percent Friday.

CEO Marvin Ellison acknowledged that Penney wasn’t strategic with promotions, which hurt profit margins, and said that its level of couponing was “unhealthy.” It plans to use a more data-driven approach to pricing this year after testing the strategy in some categories last year.

The retail chain has six locations in Maine: South Portland, Auburn, Waterville, Rockland, Bangor and Presque Isle.

Representatives at the store in South Portland and with Maine Mall management declined to comment and referred media inquiries to J.C. Penney corporate offices.

The company is due to disclose in mid-March which locations it will shut down. J.C. Penney said the affected stores account for less than 5 percent of total sales, and it expects the closures will result in $200 million of annual cost savings.

Like other department stores, J.C. Penney is trying to adjust to changing shopping patterns. But it is also still recovering from a catastrophic reinvention plan under a former CEO that sent sales and profits freefalling starting in 2012.

Since then, it has focused efforts on its home area, started selling major appliances again and expanded its number of in-store Sephora beauty shops.

While its annual sales still shrank, what’s encouraging is Penney’s profit picture.

Penney pulled in a $1 million profit for the full fiscal year, the first time it earned an annual profit since 2010. The stores it is closing represent about 13 percent to 14 percent of its current store count of about 1,000.

“With a slimmed-down store portfolio, (J.C. Penney) will be able to focus on making its remaining stores more of a destination,” said Neil Saunders, managing director of GlobalData Retail. “This is essential, as while progress has been made on categories like home, other departments still require attention.”

Penney nonetheless still managed to outperform some of its rivals.

Kohl’s Corp. reported a drop in fiscal fourth-quarter profit as total sales declined. Revenue at stores opened at least a year dropped 2.2 percent.

Nordstrom Inc. reported a better-than-expected quarterly profit with help from strong sales online and at Nordstrom Rack. But at the Nordstrom brand, comparable store sales decreased 2.7 percent.

Macy’s, the nation’s largest department store chain, says its earnings for the quarter that includes the holiday period dropped nearly 13 percent, hurt by lower sales, store closures and other costs.

Penney shares fell 9 percent, or 62 cents, to $6.24 on Friday.