[What you need to know to start the day: Get New York Today in your inbox.]

Amazon on Thursday canceled its plans to build an expansive corporate campus in New York City after facing an unexpectedly fierce backlash from lawmakers, progressive activists and union leaders, who contended that a tech giant did not deserve nearly $3 billion in government incentives.

The decision was an abrupt turnabout by Amazon after a much-publicized search for a second headquarters, which had ended with its announcement in November that it would open two new sites — one in Queens, with more than 25,000 jobs, and another in Virginia.

Amazon’s retreat was a blow to Gov. Andrew M. Cuomo and Mayor Bill de Blasio, damaging their effort to further diversify the city’s economy by making it an inviting location for the technology industry.

The agreement to lure Amazon to Long Island City, Queens, had stirred intense debate in New York about the use of public subsidies to entice wealthy companies, the rising cost of living in gentrifying neighborhoods, and the city’s very identity.