Best Buy has gone from Amazon’s showroom to a rising competitor to the e-commerce giant.

The consumer electronics retailer handily beat Wall Street expectations on both the top and bottom lines in the quarter ended July 31, with net income 56% higher than analysts were penciling in. Even compared with the pre-pandemic year, its revenue grew 24%. Best Buy’s shares jumped 6.4% Tuesday morning after its earnings call.

A return to bricks-and-mortar shopping is clearly helping. Revenue through Best Buy’s stores last quarter was higher compared with the pre-pandemic period even though it was working with fewer stores, the company noted on its Tuesday call. At the same time, the share of online sales doubled over the same period.

Chip shortages don’t seem to be crimping sales much, either. The company said that except for home theater and appliances, both of which are among the company’s the highest growing sales categories, product availability didn’t affect sales growth. It also said inventory levels look healthy for the rest of the year, including the holiday season. Accordingly, Best Buy raised its guidance for the second half of the year, expecting comparable-store sales to be flat or down 3% compared with last year’s elevated levels. It previously anticipated a high single-digit percentage decline.

Best Buy’s strong vendor relationships could prove key if product availability remains tight for retailers generally for the rest of the year. Certain gadget sellers such as Sonos and GoPro, in particular, have already announced shifts toward more direct-to-consumer sales through their own websites. While that may pinch smaller retailers, it is likely to benefit large retailers such as Best Buy if it means it is one the few preferred retailers still carrying those products. It is already clear that Best Buy continues to take market share: Its quarterly revenue growth compared with 2019 was more than double the industrywide figure for electronics and appliances over the same period, according to Census Bureau data.

Meanwhile, the company is also on track to compete more directly with Amazon Prime. By the end of next quarter, Best Buy expects to roll out its pilot membership program—Best Buy TotalTech—nationwide. Although the retailer already has a membership program, the new program adds Prime-like features such as exclusive member pricing and free shipping. Though Best Buy’s program is pricier—$199 a year compared with Prime’s $119—it could appeal to heavy gadget users. The membership includes 24/7 concierge service, for example. It also coincides with Best Buy’s expansion to other in-demand products such as patio furniture and electric mowers.

Though Best Buy has gained 19% year to date, its shares are valued reasonably. They trade at roughly 15 times forward-12-month earnings, right where their valuation was pre-pandemic, and around half the valuation fetched by the S&P 500 retailing index.

Best Buy remains an inexpensive retail bet.

Write to Jinjoo Lee at jinjoo.lee@wsj.com