Shares of Inc. (NASDAQ:AMZN) soared 18 percent in extended-hours trading Thursday after the e-commerce giant posted a surprise quarterly profit. Sales soared 20 percent from a year ago, driven by strength in North America, its largest market.

The stock soared just over 18.5 percent to as high as $572.99 in after-hours trading.

Amazon has a long history of lacking profitability, but investors continue to back the company as it sacrifices profits for rapid sales growth. Sales in North America grew 26 percent to $13.8 billion last quarter, up from $11 billion during the same period a year ago. 

Amazon closed Thursday’s U.S. trading session with a market value of $227 billion. The Seattle company is currently the No. 2 performer in the Nasdaq 100 so far this year, gaining nearly 60 percent. It is just behind movie-streaming service Netflix Inc. (NASDAQ:NFLX), which has rallied more than 100 percent since January on strong subscriber growth.

For the January-March quarter, Amazon reported a fiscal second-quarter profit of $92 million, or earnings per share of 19 cents, on revenue of $23.18 billion, compared with a loss of $126 million, or 27 cents per share, on revenue of $19.3 billion a year ago.

Wall Street had projected Amazon to report a fiscal second-quarter loss of $47.49 million, or earnings per share of 12 cents, on revenue of $22.4 billion, said analysts polled by Thomson Reuters.

In April, the e-commerce giant finally revealed sales figures for its cloud computing unit, Amazon Web Services, for the first time in a decade, offering insight into the company's core domestic operations. CEO Jeff Bezos called it a “$5 billion business” that is growing fast.

For the quarter ended June 30, the e-commerce company said its cloud business generated revenue of $1.8 billion, up from $1 billion last year.

Analysts also hope to glean a clear picture into how last week's Amazon Prime Day sale -- the one-day sale celebrating the company’s 20th anniversary -- boosted revenue in the current quarter. Sales exceeded its biggest Black Friday ever, as global order growth leaped 266 percent over the same day last year, and 18 percent more than Black Friday 2014, the company said last week. [Black Friday is the day after Thanksgiving, when early Christmas sales push many retailers into profitability for the year.]

Wall Street estimates the sale added 2 percent to unit growth for the current quarter, Gene Munster, an analyst at Piper Jaffray, said in a research note July 16.

"We continue to view Prime as one of the most important drivers of growth for Amazon and believe that this campaign will only strengthen its perceived value among consumers," Jaffray said.

Ahead of the earnings announcement, Munster gave Amazon an Overweight rating Monday with a 12-month price target of $520. 

The stock has already gained 11 percent in July.

The e-commerce giant announced in May its Amazon Prime Now service is offering one-hour delivery from local stores in Manhattan, including groceries, meals and baked goods, through the Amazon Prime Now app. Although the world’s largest retailer, Wal-Mart Stores Inc. (NYSE:WMT), has improved its e-commerce platform, that improvement comes with lower margins, price competition and higher shipping costs, making it more difficult for the retailer to take on its biggest rival, Amazon.

Wal-Mart announced in May that it’s testing a free shipping service this summer in a move to take on Amazon Prime. The service will cost $50 per year and deliver products within three days or less. Amazon Prime, by comparison, costs an annual $99 and promises deliveries in two days or less.

Although Wal-Mart’s service will be cheaper, it’s missing a key feature that draws consumers to Amazon Prime: video streaming.

Jessica Menton covers business and the financial markets. News tips? Email me here. Follow me on Twitter @JessicaMenton.