Talk about rising above low expectations.

Best Buy Co.’s shares soared nearly 20 percent on Tuesday — its biggest one-day gain in more than a decade — after reporting a surprising uptick in quarterly comparable sales when investors were expecting a slight drop.

“Best Buy continues to defy the skeptics,” David Magee, an analyst with SunTrust Robinson Humphrey, wrote in a research report.

Wall Street predicted negative results out of the Richfield-based electronics chain based on multiple troubling signs about a downward trend in consumer electronics over the summer, said R.J. Hottovy, an analyst with Morningstar. “Against that backdrop, it’s not surprising that even modestly positive results are driving the stock upward.”

The red flags included Target Corp.’s bombshell last week that its electronic sales were down double-digit percentages in the second quarter — and sales of Apple Inc. products in particular were down more than 20 percent. Wal-Mart executives also talked about softness in that segment. And recent data from the U.S. Commerce Department told a similar tale about a slide in electronics and appliance sales.

On top of that, investors had become increasingly skeptical about Best Buy’s turnaround since Chief Financial Officer Sharon McCollam — a major player in cost-cutting efforts that put the company back on stable footing — announced in May that she would step down. They were also unsettled by Chief Executive Hubert Joly’s sell-off earlier this summer of $12.8 million worth of shares he owned in the company.

Add all of that up, and in the day leading up to Tuesday’s earnings release, headlines in the financial press warned of “mounting troubles” for Best Buy and a possible imminent “crash” of its shares.

So when Best Buy posted a comparable sales growth in the U.S. of 0.8 percent, investors celebrated. The retailer, which had forecast flat sales in the May-to-July period, also posted a better-than-expected 21 percent increase in profit.

“You have to give the company a lot of credit for very good execution and what seems to us as clear market share gains,” said Peter Keith, an analyst with Piper Jaffray. “They are executing very well in a tough environment.”

Still, his firm is maintaining its neutral rating because of the overall tepid consumer electronics industry. Keith added that there continue to be concerns about the price deflation of 4K TVs and about how much of a lift Best Buy could get out a new iPhone model, which is expected to be released this fall.

Because of the industrywide decline in smartphone sales, Best Buy is sticking with its forecast for flat sales this year. But it has also lifted its profit outlook.

Best Buy attributed the better second-quarter performance to strong sales of TVs, appliances, computing and health and wearables that helped offset weakness in smartphones and video games. Also, tablet sales, which have been declining industrywide, did not perform as badly as expected.

Joly said it was also a reflection that the company’s strategy of turning its stores into destinations with mini-shops highlighting major vendors, focusing on customer service and upgrading its digital channels is paying off.

“Like any space in retail, there are winners and losers,” Joly told reporters. “It is a really hard category to be successful at, and we’ve clearly raised the bar on ourselves. It’s good to see the customers reward us.”

Best Buy’s online sales were another standout, rising 24 percent in the quarter compared to 17 percent a year ago. That continued acceleration contrasts with other retailers who have begun to see their online growth slow. Best Buy has been upgrading its website and app to improve search capability, provide summaries of customer reviews and streamline the checkout process. It’s also now often getting packages to customers’ doorsteps in two days or less.

“And it’s free — you don’t have to pay a subscription to get that service,” Joly said in an obvious jab at Amazon’s $99-a-year Prime program that has set industry expectations with free two-day delivery.

At the same time, about a third of Best Buy’s online orders are picked up in stores.

Charlie O’Shea, an analyst with Moody’s, said Best Buy’s online growth is especially notable since it was up against Amazon’s Prime Day sales bonanza in July and a steady stream of offers from Wal-Mart. It is “evidence that a well-managed brick-and-mortar retailer with a well-thought-out strategy that successfully utilizes its physical assets can thrive as it transitions to a true multichannel retailer.”

In the three months ended July 30, Best Buy’s net income rose to $198 million, up from $164 million in the same quarter a year ago. Adjusted for one-time expenses, Best Buy earned 57 cents a share, which was better than the 43 cents a share analysts were expecting and the 38 to 42 cents range the company had forecast.

Overall revenue was $8.5 billion, better than the expectations and basically flat compared to last year.

Best Buy’s stock closed Tuesday at $39.23, up $6.43.

Looking forward, Joly said he expects 4K TVs, appliances and connected home products to continue to be productive categories.

While he doesn’t expect virtual reality to make a significant dent in sales this year, he noted that many Best Buy stores will be destinations for demos of the newer technology and would likely be a driver of growth further down the road.

“It’s just mind-boggling,” he said and recounted a recent memorable experience trying it out himself. “I was almost eaten alive by a shark!”

But he wasn’t. And neither was Best Buy.