posted a narrower quarterly loss and better-than-expected sales on Thursday as the company expanded aggressively in the United States and made inroads into overseas markets, sending its shares up more than 8 percent in after-hours trading.

The sales results underscored Amazon’s strong momentum as the company — the world’s largest Internet retailer — prepares for the crucial U.S. holiday season, which some experts say could be the slowest in years.

Rival eBay gave a disappointing holiday forecast last week, saying the U.S. economy, including consumer confidence, had deteriorated in part because of the government shutdown.

Amazon forecast sales of $23.5 billion to $26.5 billion for the holiday quarter, which analysts called conservative.

“It’ll be a somewhat difficult macro environment in the fourth quarter,” said Morningstar analyst R.J. Hottovy. “But it looks like the revenue momentum will continue into the fourth quarter.”

Amazon became the latest tech company to have outperformed in an otherwise dreary earnings season. About 84 percent of technology companies that have reported so far beat earnings estimates, and 63 percent have beat revenue projections.

Amazon’s third-quarter revenue was $17.1 billion, up from $13.8 billion in the comparable period a year earlier. The average analyst estimate was $16.8 billion.

Amazon is trying to evolve from an online retailer into a broader technology company offering consumer gadgets such as tablets and cloud-computing services to companies and governments.

The evolution has entailed making investments in technology and content, such as videos and music, all while building distribution centers across the United States and expanding its presence in competitive overseas markets such as China.

Amazon is spending billions of dollars to expand, and that has taken a toll on earnings. But some investors think the move will pay off as the spending tapers and margins expand.

Amazon’s gross profit margin — a closely watched measure of earnings that excludes several expenses — was 28.6 percent in the second quarter, one of the highest levels in more than a decade by analysts’ reckoning.

Third-quarter margins were about 28 percent, in line with what analysts had expected.

The company’s net loss was $41 million, or $0.09 per diluted share, narrowing from a net loss of $274 million, or $0.60 per diluted share, in the third quarter of 2012.

Amazon’s stock has gained about 30 percent this year and is valued at 131 times its projected 2014 earnings, among the highest valuations in the market. In after-hours trading on Thursday, Amazon shares climbed more than 8 percent, to about $362, from the closing price of $332.21.

“The takeaway is that the third-quarter sales show that the Amazon value proposition is striking a chord with consumers,” Hottovy said.

(Amazon founder and chief executive Jeffrey P. Bezos owns The Washington Post.)

— Reuters