Tech giant Amazon (AMZN 0.58%) smashed expectations last quarter, showing it made big improvements in profitability. The good news for investors is that this doesn't look to be a one-off result. Amazon's margins are stronger, especially in its largest segment.

That data point has investors impressed with the company and buying the stock again. Here's why.

The company's North America business is back to generating strong margins

In the midst of Amazon's supersized growth during the pandemic, the company, along with others in the tech industry, hired staff aggressively. Ultimately it overestimated how strong demand would be and ended up adding too many resources. That led to worsening margins, particularly in the company's North America operations, which account for the bulk of Amazon's overall revenue.

But with Amazon laying off staff and working on improving its margins over the past year, there has been a big improvement in the segment. Last quarter, which ended June 30, the segment's operating margin was up to 4% -- the highest it has been in two years. During the period, North America operating income totaled $3.2 billion, which was a huge improvement from the $627 million loss it incurred a year earlier.

Amazon's North American operating income.

Image source: Company filings. Chart by author.

Amazon's international segment was the only one to report negative operating income. Overall, the company's consolidated operating profits totaled $7.7 billion and were more than double the $3.3 billion that Amazon posted a year ago.

Amazon improved margins even as sales grew

Amazon's growth rate declined in recent quarters as the pandemic-fueled boom in spending receded. But a positive sign is that even as the company worked on reducing its expenditures, all of its major segments reported at least 10% year-over-year revenue growth last quarter. 

Amazon sales growth by segment.

Image source: Company filings. Chart by author.

Achieving double-digit percentage revenue growth while also cutting down on costs is a big accomplishment for the business. And while growth investors may be discouraged by the declining growth rate, it's likely a bump in the road for the behemoth. As economic conditions improve, there should be an improvement in the company's growth rate. Amazon also launched Bedrock, which helps companies build artificial intelligence (AI) applications, which may be another growth catalyst down the road.

Most importantly, Amazon got back to growing its business more efficiently.

Is Amazon stock a buy?

In light of the stronger performance this year, share prices of Amazon are up nearly 60% year to date. The S&P 500, by comparison, is up by just 14.3%. Amazon stock trades at a hefty 106 times earnings but with the business looking like it's on the right track and profitability potentially improving as the year goes on, that multiple should come down over time. Analysts boosted their price targets for the tech stock, with its upside now around 20%.

Amazon may seem expensive now, but for long-term investors, it can be an excellent buy. Its fundamentals are stronger and the company's growth opportunities remain plentiful.