Walmart, the giant retailer, said Tuesday that it had attracted more customers during the crucial holiday shopping season but that its efforts had come at a cost.

Sales at U.S. stores open at least a year rose 1.8 percent during the fourth quarter, compared with a 1.3 percent increase many analysts were expecting, Walmart reported. But profits fell 18 percent during that period to $3.8 billion, or $1.22 a share.

Big-box retailers such as Walmart have been struggling in recent years as customers did more of their shopping online. Walmart has responded by opening fewer stores while bolstering its online operations. That focus paid off during the holiday shopping season when online sales increased 29 percent.

“We’re moving with speed to become more of a digital enterprise and better serve customers,” Doug McMillon, Walmart’s president and chief executive, said in a statement. “We have more work to do, but I’m pleased with our progress.”

Last month, Walmart announced that it would be offering free two-day shipping for millions of items, in another bid to take on Amazon.com’s online shopping dominance. (Jeffrey P. Bezos, the chief executive of Amazon, owns The Washington Post. )

“All in all, we believe Walmart is continuing to generate critical and increasing traction online, with the current fiscal year another year of investment in this channel,” Moody’s lead retail analyst, Charlie O’Shea, said in a research note.

[Walmart’s latest bid to battle Amazon: Free two-day shipping on 2 million items, without a membership]

The retail industry was largely expected this year to post solid holiday sales: Consumer confidence is high, and growth in online spending was robust in December. But some large retailers struggled, including Macy’s.

The department store reported Tuesday that sales at stores open at least one year fell about 2 percent during the fourth quarter and that profits fell about 13 percent. The company has already said it would slash 10,000 jobs as it continues to struggle to reinvigorate itself.

“Frankly, it wasn’t the year we expected, nor hoped for, and we’re not happy at all,” Terry J. Lundgren, Macy’s chairman and chief executive, said in a conference call with analysts, his last before turning over the CEO reins to Jeff Gennette.

Lundgren, who will become executive chairman, said Macy’s had closed 66 stores and planned to shutter 34 more in the next few years to put the retailer on firmer footing, noting that 90 percent of the merchandise Macy’s sells is still sold in stores.

“Macy’s is making a little more progress in terms of the future structure of the organization,” Neil Saunders, managing director of GlobalData Retail, said in a research note. “There now seems to be a realization that the company must move faster if it is to survive.”

Meanwhile, Home Depot, the world’s largest home-improvement chain, said sales at stores open at least a year rose 5.8 percent during the fourth quarter. The retailer said it would buy back $15 billion in its own stock, further bolstering its share price, which is up 7 percent this year.

At Tuesday’s close, Walmart gained 3 percent, while Macy’s was flat. Home Depot closed up about 1.4 percent.

Lundgren spent part of his final conference call with analysts talking about the ups and downs he has experienced in his 14 years as chief executive at Macy’s and six years as CEO of Neiman Marcus before that. He sounded an optimistic note about the chain’s ability to rebound from recent setbacks.

“There’s lots of concern out there about our ability to bounce back, but yet internally, so many of the people that are on our team have seen this movie or some version of it in the past and get excited about taking on that challenge,” he said.