The e-commerce giant said net income was $92 million, or 19 cents a share, in the three months ended June 30. That's compared with a net loss of $126 million, or 27 cents a share, in the same period a year ago. Analysts were expecting a loss of 15 cents a share, according to FactSet.
Revenue also jumped 20% to $23.2 billion.
That news pushed Amazon stock up as much 20% on Friday. As of mid-afternoon trading, Amazon was up nearly 11% to $533.33. That boosted the company's market value to about $249 billion, more than Wal-Mart's market value of nearly $231 billion.
Amazon.com is trying to venture into areas beyond its domain of books and household goods. The company has gotten into grocery delivery and also offers free movies and TV shows for Amazon Prime members, who pay $99 a year for perks including free two-day shipping.
Amazon has been battling with Wal-Mart and other retailers for shoppers who continue to be reticent about spending.
Last week, the online retailer offered a one-day shopping event called "Prime Day," with more discounts than Black Friday.
Not to be outdone, Wal-Mart also offered a big sale on the same day with thousands of discounts. Wal-Mart is also testing out a similar free-shipping program to its shoppers for an annual fee of $50.
Follow Shan Li on Twitter @ByShanLi