• Shares gain in early trading after chain tops estimates
  • Customer traffic increases the most in more than two years

Target Corp. delivered another sign that its comeback is taking hold as stronger online sales helped brighten the retailer’s outlook.

Second-quarter sales topped analysts’ estimates on Wednesday, and the company boosted its forecast for the rest of the year. That helped soothe investors after a rocky earnings season for retailers, sending Target shares up as much as 4.9 percent.

The results show that Target is improving in both online sales and customer traffic — two areas where it’s been losing ground to Wal-Mart Stores Inc. They also lend credence to a $7 billion turnaround plan laid out in February by Chief Executive Officer Brian Cornell. He aims to refurbish stores, open more small locations in cities and speed delivery of online orders.

Target needs to up its game as Wal-Mart reduces prices and Amazon.com Inc. expands its lineup in categories like apparel and beauty, which have long been strongholds of Minneapolis-based Target.

“It is encouraging to see some progress against their turnaround plan, and that they were finally able to generate some positive traffic,” said Jennifer Bartashus, an analyst at Bloomberg Intelligence. “They took a very conservative approach to second-quarter guidance, so it isn’t a huge surprise that they were able to beat those expectations.”

Same-store sales increased 1.3 percent in the second quarter, fueled by a 32 percent boost in online revenue and a 2.1 percent gain in customer traffic — the biggest…