Amazon's second-quarter earnings fell short of Wall Street estimates, though sales topped expectations.

The online retailer is spending more heavily on its delivery infrastructure amid growing competition from companies such as Walmart and Target

Amazon reported a rare shortfall in profit Thursday as its latest earnings fell short of Wall Street forecasts.

The Seattle-based company says profits for the three-month period ended June 30 was $2.62 billion, or $5.22 per share. That compares with $2.53 billion, or $5.07 per share, in the year ago quarter. Analysts had expected earnings per share of $5.56 per share, according to FactSet.

Amazon had pledged to spend $800 million in the second quarter to move to one-day delivery from two-day delivery for its Prime members who pay $119 a year. The service is now available on more than ten million items.

Get Breaking News Delivered to Your Inbox

"Customers are responding to Prime's move to one-day delivery — we've received a lot of positive feedback and seen accelerating sales growth," said Jeff Bezos, Amazon founder and CEO in a statement.

The move comes as Amazon faces increasing competition from the likes of Walmart and Target, both of which are speeding up deliveries. Walmart is offering next day delivery for shoppers in Phoenix, Arizona, Las Vegas and southern California. and plans to roll out the service to 75% of the U.S. population by year-end.

The company said net sales rose 20% to $63.4 billion. That's higher than the $62.5 billion forecast by analysts. Amazon offered revenue outlook for the current quarter in line with analysts' expectations.

Amazon's latest "results were negatively impacted by margin compression in North America due to the investments in next day Prime delivery, which we continued to believe is an example of short-term pain for long-term gain, and is a necessary strategy to compete with brick-and-mortar's speed advantage to the customer," Moody's Amazon analyst Charlie O'Shea said in a note.

Amazon shares fell 1.5% to $1,945 in after-hours trading. The company had posted record profits for four consecutive quarters.

Google, Facebook going strong despite fed scrutiny

The report comes as Amazon, along with Facebook, Google and Apple, is caught up in the swirl of investigations into Big Tech's market dominance.

Google parent Alphabet beat analyst expectations for the second quarter Thursday, pleasing investors and sending its shares up sharply.

The Mountain View, California-based company brought in revenue of $38.9 billion during the quarter, a 19% bump from the same period last year. The company reported profit of $14.21 per share, or $9.9 billion during the quarter, nearly triple what it made last year when it paid a $5.1 billion European Commission fine.

Analysts polled by FactSet were expecting Alphabet to report earnings per share of $11.10 on revenue of $38.2 billion during the second quarter.

Google's stock rose more than 7% in after-hours trading immediately after the earnings report was released.

The company did not disclose anything about federal regulatory concerns in its quarterly report - unlike Facebook, which said Wednesday that the Federal Trade Commission is investigating it for antitrust concerns.

Facebook on Wednesday reported robust quarterly earnings of $4.6 billion on $16.9 billion in revenue. Legal expenses related to the FTC settlement shrank the company's profit margin to 27%, down from 44% in the year-ago period.