Seattle officials scuttled a corporate tax on Tuesday that they had wholeheartedly endorsed just a month ago, delivering a win for the measure’s biggest opponent — Amazon — and offering a warning to cities (such as Raleigh. Durham and the research Triangle) bidding for the retailer’s second headquarters that the company would go to the limit to get its way.

The tax would have raised about $50 million a year to help the homeless and fund affordable housing projects. As Seattle has boomed over the past decade, in large part because of Amazon, which is based there, rents have soared and some residents have suffered. The city’s homeless population is the third largest in the country, after New York and Los Angeles.

Taxing successful companies to help alleviate some of the problems that their success caused was such a compelling idea that it was quickly taken up in Silicon Valley itself. California cities like Cupertino, East Palo Alto, Mountain View and San Francisco have recently explored various forms of a head tax, under which large employers in each town would be charged a fee per employee.

But in Seattle, the notion has proved extraordinarily contentious, culminating in the abrupt reversal Tuesday.

The Seattle City Council repealed the tax in a 7-2 vote that was accompanied by large doses of acrimony and despair. The crowd was standing room only, with some carrying posters that said “Tax Amazon Not Working People” while others supported repeal. The comment period was extended by the council members in a fruitless attempt to try to accommodate everyone. At least one Amazon employee spoke in favor of the tax, saying “I want all kinds of people in this city, not just rich people.”

Less than a month ago, the tax had passed unanimously. It was signed into law on May 16 by Jenny A. Durkan, Seattle’s mayor, who said the money would “move people off the street and into safer places” and “clean up the garbage and needles that are in our parks and in our communities,” as well as provide resources including job training and health services.

“I know we can be a city that continues to invent the future and come together to build a more affordable, inclusive, and just future,” she said.

Within days, that vision was in tatters. Amazon, which had already succeeded in watering down the original tax after halting expansion plans in protest, joined other Seattle-based corporate interests such as Starbucks, Microsoft co-founder Paul Allen’s investment firm Vulcan and local food and grocery firms. All showed they would fight the law, and at least some residents took their side.

The opponents funded No Tax on Jobs, an effort aimed at getting enough signatures to put a repeal on the November ballot. It became obvious over the weekend that the measure would succeed in coming before voters, leading Durkan and seven council members to issue a statement saying, “We heard you.”

The politicians had no stomach for a protracted battle over jobs, even at a moment when the area’s unemployment rate is only 3.1 percent. “It is clear that the ordinance will lead to a prolonged, expensive political fight over the next five months that will do nothing to tackle our urgent housing and homelessness crisis,” they said.

An Amazon spokesman called the vote “the right decision.” A Starbucks spokesman said, “We welcome this move.” Mike O’Brien, a City Council member, said in an interview before the vote, “I have a couple of bad choices and I’m picking the less bad,” meaning a vote to repeal.

He was puzzled by the intensity and the virulence of the opposition. “This tax is not a perfect tool, but I think it’s a good one,” he said. “When I’m out there talking to the community, I hear they’ve been convinced by Amazon and other business leaders that this would be bad.”

Teresa Mosqueda, one of the two council members opposing the repeal, said there was no backup plan for dealing with the homeless situation.

“We don’t have a path forward,” she said. “I share the frustration with all the City Council that we have been out-messaged.”

Kshama Sawant, the other opponent of repeal on the council, called the vote “both capitulation and betrayal.”

“They are choosing to base themselves on making Amazon executives happy,” she said. That “is the biggest lesson that should reverberate to other cities as well.”

The city’s initial plan was for the tax to collect about $500 per employee a year. Amazon responded in early May by stopping its expansion in the city “pending the outcome of the head tax vote.” That was sufficient to get the tax knocked down to about $275 per employee and scaled back in other ways. The tax was limited to companies with at least $20 million in revenue a year.

As the largest private employer in the city, with more than 45,000 local workers, Amazon would have had to pay initially about $12 million a year — a relative pittance for a company with revenue last year of $178 billion and whose chief executive, Jeff Bezos, the richest man in the world, said recently that the only thing he could think of to spend his fortune on was space travel.

Amazon officials have said the company is not against helping the homeless. But it thinks Seattle would just waste the money it raised. The city, the company believes, “has a spending efficiency problem.”

The retailer selected 20 finalists in January as possible sites for its new second headquarters, a process that has generated an enormous amount of attention and interest, even by Amazon’s standards. It has indicated that the community that won the right to as many as 50,000 new jobs would have to be an accommodating partner. Some of the finalists have offered extraordinary tax breaks.

In recent months, however, there has been the beginning of a resistance to the notion that what is good for Amazon is inevitably good for its host.

“From coast to coast, people lose their homes and get displaced from their communities even as the biggest corporations earn record profits and development booms,” said Sarah Johnson, director of Local Progress, a national association of progressive elected municipal officials. “Elected officials across the country are paying close attention to how Amazon and other corporations have responded to Seattle’s efforts to confront their affordable housing and homelessness crisis.”

Especially, it seems, in Silicon Valley itself, where both problems run deep.

Last week, the Mountain View City Council voted unanimously to proceed with plans to put a head-count tax on the ballot in November. Mountain View is home to Google, among other tech companies. The tax would raise about $6 million, half of it from Google, and be used for transit projects.

“We have needs we need to meet,” said Lenny Siegel, the city’s mayor. “And we look to see where there’s the most money. Most of our companies have money. We’re trying to find a way for them to invest it that helps them and the community.”