Amazon's revenue jumped 20% from the year-ago period, a rebound from 16.8% in the first quarter, which was the slowest in four years. The recovery follows Amazon's pledge to spend $800 million in the second quarter improving warehouses and delivery infrastructure as part of a plan to make one-day shipping the standard for Prime members. Analysts predict that shorter delivery times will lead to more frequent purchases and higher revenue.

Amazon's shares, however, dropped over 2% in after-hours trading, as the company gave third-quarter profit guidance that fell well-below street estimates.

The results show Amazon's renewed investments into the company are paying off, driving sales growth at the expense of lower profit margins.

But all that spending is cutting into Amazon's profit margins, resulting in lower-than-expected earnings. Amazon's net income of $2.6 billion was the lowest since the second quarter of last year, putting an end to a record profit streak of four straight quarters. The company forecast third-quarter operating income in the range of $2.1 billion to $3.1 billion, which is far lower than FactSet estimates of $4.4 billion. Chief Financial Officer Brian Olsavsky said on Thursday's earnings call that the company spent slightly more than $800 million on its expansion plans in the quarter.

"Q2's results were negatively impacted by margin compression in North America due to the investments in next day Prime delivery, which we continue to believe is an example of short-term pain for long-term gain," Moody's Amazon Analyst Charlie O'Shea said in an email statement.

CEO Jeff Bezos said in the earnings release that the change has resulted in "a lot of positive feedback" and "accelerating sales growth."

"Free one-day delivery is now available to Prime members on more than ten million items, and we're just getting started," Bezos said in the statement.

Amazon Web Services, its most lucrative business, reported 37% growth, trailing analysts' estimates and indicating that Microsoft is picking up steam. The growth in AWS, which provides computing and storage for corporations, schools and government agencies, slipped from 41% in the previous quarter.

In the "Other" category, which includes Amazon's increasingly important online ad business, revenue climbed 37% to $3 billion. International sales grew 12% to $16.4 billion, down from last year's 27% growth. Physical stores, which includes Whole Foods, remained roughly flat at $4.3 billion in sales, but the company said it would have grown over 5% if it included home delivery and in-store pick-up orders, both booked under online sales instead.

Meanwhile, the company is facing heightened regulatory scrutiny, with antitrust officials in the U.S. and EU launching investigations into the company's business practices. Thursday's results, however, don't include the impact of any potential regulations or penalties, Olsavsky said.

Earlier this month, Amazon held Prime Day, its biggest shopping event of the year. The company said it set another sales record during the two-day sales promotion, which is likely why Amazon's third-quarter revenue guidance of $66 billion to $70 billion exceeded street estimates of $67.3 billion, according to FactSet.

During the second-quarter, Amazon rolled out a new round of discounts across hundreds of products at its Whole Foods stores, while expanding the grocery chain's delivery footprint to more regions in the U.S. The company also announced a partnership with Rite Aid that allows customers to pick up their Amazon packages in-store.

In June, Amazon's first re: Mars conference took place, where Bezos shared more details on Project Kuiper, its plan to launch over 3,200 satellites to improve broadband connection.

Amazon shares have climbed 32% this year, outpacing the 20% gain for the S&P 500.

WATCH: Big Tech under pressure on antitrust concerns — Here's five experts on what investors should watch