Best Buy Co., the electronics giant left for dead a few years ago, is bucking America’s retail slump by turning its cavernous stores from a potential drag on its business into a way to fend off Amazon.com Inc.

The company Thursday reported a slight increase in quarterly revenue, surprising investors who were bracing for a decline. Online sales jumped 23% in the U.S. from a year ago, accounting for $1 billion of business in the quarter and offsetting in-store declines.

...