Second-quarter sales rose 39 percent to $52.9 billion. (Mike Segar/Reuters)

Amazon.com’s quarterly profit hit a record $2.5 billion, the technology giant announced Thursday, as it races to become the world’s first trillion dollar company.

Profit rose 12-fold from a year earlier, while second-quarter revenue climbed 39 percent to $52.9 billion.

This marks the 13th consecutive quarter of profits for Amazon, which didn’t turn a profit for years as it reinvested in its business. (Jeffrey P. Bezos, the founder and chief executive of Amazon, owns The Washington Post.)

“Amazon posted a blowout quarter by virtually any measurement,” said Charles O’Shea, lead retail analyst for Moody’s.

Amazon Web Services, the company’s cloud-computing business, again accounted for much of its growth. During the second quarter, it brought in $6.1 billion in sales, a 49 percent increase from $4.1 billion a year ago. Another fast-growing source of revenue: Amazon’s advertising business, which helped bring in $2.2 billion for the company, more than double what it did a year ago.

Amazon’s stock spiked about 4 percent to $1,870 per share in after-hours trading following the news. The company’s stock is up 57 percent so far this year.

Amazon is going toe-to-toe with Apple and Google’s parent company, Alphabet, to reach $1 trillion market capitalization. Amazon’s is currently at $861 billion. Apple, meanwhile, has a market cap of $946 billion, while Alphabet’s is $877 billion.

Overall for the three months ended June 30, profit totaled $2.5 billion, or $5.21 per share, up from $197 million, or 41 cents a share, a year earlier.

About half of the company’s quarterly revenue came from its flagship e-commerce business, which delivered $27.2 billion in the second quarter. But as online sales grew, so did shipping costs: Amazon spent nearly $6 billion mailing out packages in the second quarter, a 31 percent increase from a year ago.

“We’re really pleased with the retail growth,” Brian T. Olsavsky, Amazon’s chief financial officer, said in a Thursday afternoon earnings call. “We think it’s driven by the Prime program, as well as increased selection, particularly third-party selection.”

The retail behemoth has been growing at breakneck speed as it expands into a number of new industries, including health care, advertising and movie production. Last month, Amazon made its first foray into the pharmacy business when it announced plans to buy PillPack, which sells presorted medicine online.

Its purchase of Whole Foods Market last summer gave Amazon something it had long lacked: a nationwide network of physical stores. The company’s brick-and-mortar stores generated $4.31 billion in second-quarter revenue. Since taking over Whole Foods, Amazon has lowered prices and expanded same-day delivery in a bid to attract more shoppers to the grocery chain.

But Amazon’s eye-popping growth has also led to increased scrutiny over the possibility that the company’s market dominance gives it monopoly power. President Trump has been a vocal critic of the company — and its founder’s ownership of The Washington Post. Earlier this week, he lashed out again against Amazon on Twitter, saying that “many feel” there may be antitrust concerns related to the company.

Amazon’s Prime membership program, which costs $119 a year, now has more than 100 million members worldwide.

The quarterly results do not include sales from last week’s Prime Day, the company-created discount event that brings in billions of dollars for Amazon. This year, the company said it sold more than 100 million items during the 36-hour sale, though it did not disclose sales figures.

Read more:

Is Amazon getting too big?

A Toys R Us death blow: Mattel to lay off 2,200 workers

The end of Ivanka’s fashion brand kicks off a buying frenzy among her fans

How Amazon’s contract to sell office supplies to cities could hurt local retail