Amazon's quarterly profit soared past $2 billion for the first time as its online shopping, cloud computing and advertising businesses kept growing.

The company, which has expanded far beyond its online bookseller beginnings, is also moving into health care and building up its physical presence as it cements customer loyalty through its smart devices and Prime membership of shipping and streaming perks.

Revenue soared 39 percent in the second quarter, but missed analysts' expectations.

The financial results still pleased investors, who sent its shares up more than 3 percent to $1,866.55 in after-hours trading. Its stock is already up nearly 72 percent in the last year, and Amazon is getting closer to surpassing iPhone maker Apple as the world's most valuable company.

Amazon did suffer a rare setback last week, when its Prime Day sales event began with technical issues. Some shoppers saw pictures of dogs with an apologetic message instead of the products they wanted to buy, and took to social media to complain.

Chief Financial Officer Brian Olsavsky said Thursday that the glitch was caused by "larger than expected traffic" to the site. Despite the early issues, Amazon said this year's Prime Day was its biggest shopping event in its history and more new Prime members signed up on July 16 than on any other day.

Amazon
Amazon boxes are seen stacked for delivery in the Manhattan borough of New York City, U.S., Jan. 29, 2016. REUTERS/Mike Segar

Revenue for the quarter came to $52.89 billion, below the $53.37 billion analysts expected. The company's physical stores brought in $4.3 billion, most of which came from its Whole Foods grocery chain. Amazon, which bought Whole Foods last year, recently rolled out extra discounts for its Prime members at its U.S. stores.

Outside of retail, Amazon's Web Services unit — which provides cloud computing services to companies and government — has been a strong source of income and has helped offset the high costs associated with running its online store. More recently, its advertising unit has become a multi-billion dollar business, selling ads to companies that want their products to show up first when shoppers search on the site.

Amazon also announced last month that it is buying the online pharmacy PillPack, pushing it deeper into the health care industry. When asked about the deal Thursday, Amazon executives gave no details on its plans for PillPack. The deal is expected to close later this year.

For the three months ending June 30, Seattle-based Amazon reported net income of $2.53 billion, or $5.07 per share, blowing past the $2.48 per share Wall Street analysts expected, according to FactSet.

Looking ahead to the third quarter, Amazon said it expects to report revenue between $54 billion and $57.5 billion, below the $58.1 billion Wall Street analysts expected.