Amazon.com Inc. abandoned its $2.5 billion plan to build a New York City headquarters, undoing one of the country’s biggest economic-development deals because it said it was troubled by growing political opposition to subsidies to one of the world’s richest companies.

The move reverses Amazon’s very public, yearlong sweepstakes that sparked bids from more than 200 locales around the country and left Northern Virginia and New York City the winners.

The retreat, less than a week after news that the retailing and computer services powerhouse was having second thoughts, will cost New York 25,000 potential jobs on a new campus that was to be located in Long Island City, Queens, across the East River from Manhattan.

Amazon had agreed to spend up to $2.5 billion to build the new campus and bring at least 25,000 workers to the location over the next decade. In exchange, New York City and the state offered $3 billion in tax incentives.

The deal’s detractors, including some state and city elected officials, called it corporate welfare and opposed Amazon’s antiunion stance and resistance to organizing its New York employees.