As the pandemic gripped New York City, it propelled an enormous surge in online shopping. Amazon, the giant online retailer, went shopping too.

Amazon has spent the pandemic embarking on a warehouse shopping spree in New York, significantly expanding its footprint.

It has snatched up at least nine new warehouses in the city, including a behemoth rising in Queens that, at one million-plus square feet, will be its largest in New York, and today has at least 12 warehouses in the five boroughs. And it has added more than two dozen warehouses in suburbs surrounding the city.

No other large competitor has a single warehouse in the city and Amazon has largely left most of its chief rivals, like Walmart and Target, behind.

“Amazon had people making deals,” said Adam Gordon, whose real estate firm Wildflower owns several warehouses in the city. “And they were outcompeting.”

New York City is the biggest and most lucrative market in the United States. That helps explain the expansion by the company just two years after it abruptly scuttled plans to build a gleaming new headquarters in Long Island City, Queens.

New York has about 128 million square feet of industrial space, far less than many smaller cities (not to mention narrow streets and a brutal lack of parking).

Many packages come to New York from New Jersey and Pennsylvania, where there is room to build bigger and cheaper warehouses. And in the past year, Amazon has added 14 new warehouses in New Jersey and on Long Island, totaling more than seven million square feet.

But having warehouses in the city is more cost effective and can trim roughly 20 percent off delivery expenses compared with deliveries that originate in New Jersey. Amazon, which owns Whole Foods, has also used the grocery stores to fulfill online orders, with its workers often outnumbering store customers.

Roughly 2.4 million packages are delivered in New York City every day, nearly half a million more than before the pandemic, and city data shows that 80 percent of deliveries are to residential customers, compared with 40 percent before the outbreak.

“We are excited to continue to invest in the state of New York by adding new delivery stations,” said Deborah Bass, an Amazon spokeswoman, adding that the company’s goal was to “become part of the fabric of New York City by embracing the people, the needs, and the spirit of the community.”