Amazon took the unusual step of suppressing demand. And it has been battling the spread of the virus among its warehouse employees, who have been pressuring the company to provide more leave and safety precautions.

On a call with reporters, the company declined to say how many of its workers had tested positive for the virus.

Amazon’s grocery business got a major boost, with sales up 8 percent in its physical stores, which are mostly Whole Foods locations. They had largely been flat for at least a year.

While Americans had been slow to adopt online grocery shopping, the pandemic created the shove that many needed to change behavior, at least temporarily. Mr. Olsavsky said the company had increased grocery delivery capacity more than 60 percent in the quarter and still could not meet demand. The company has set up a waiting list for new customers.

Analysts had expected profits to shrink slightly. Amazon has hired more people to work in its warehouses and raised wages $2 an hour, with additional increases for overtime. The company hired about 80,000 warehouse workers in March, and 95,000 more in April. Some of those new hires were filling in for employees who stayed home because of the pandemic.

Also, the mix of what customers are buying has shifted to less profitable types of products. Normally, more than a third of surveyed Amazon customers say they bought clothing on the site in the previous month, but that fell to 27 percent in March, according to the investment bank Cowen & Company. Usually, a quarter of shoppers had recently bought consumable products like toilet paper on Amazon, but in March that jumped to 33 percent, the bank said.

“No one likes to sell essentials because that’s a lower-margin business,” said Ron Josey, an analyst with the investment bank JMP Securities.

Amazon’s cloud computing business grew 33 percent, to $10.2 billion in sales, just shy of what analysts expected. There has been demand for streaming products, like gaming, that are built on Amazon’s cloud infrastructure, Mr. Olsavsky said, but “hospitality and travel have contracted very severely, very quickly.”