For months, Andrew Yang seemed like he was exactly what New York City was looking for in a mayor.He was relentlessly positive at a time when the city, still locked down during the pandemic, was somber. While other candidates were stuck in a loop of online mayoral forums, he seized attention by holding in-person events, capitalizing on his star power as a 2020 presidential candidate.He leapt to the top of polls, drawing the affection of wealthy donors and envy from the race’s more established candidates. But as the race’s sudden front-runner, Mr. Yang began to draw more scrutiny from the news media and his rivals, and bit by bit, he lost ground.Eric Adams was the first to pass him, and others would follow. By primary night, Mr. Yang was the first candidate to concede, far back in fourth place.His collapse was a result of an accumulation of factors: self-inflicted wounds, a perception that he was out of his depth, and the city’s changing environment.The pall that had fallen over New York had started to lift: Mr. Yang had campaigned on reopening the city, but the city had reopened without him. And now New Yorkers seemed far more worried about crime, an ideal scenario for Mr. Adams, a former police captain and the current Brooklyn borough president.Mr. Yang tried to change his message and tone, but the shift was too late and seemed to alienate some of his core followers.In the early stages of the mayoral campaign, Mr. Yang held far more in-person events than his rivals.Chang W. Lee/The New York TimesIn interviews with campaign staffers and surrogates, supporters and opponents, the diagnoses of Mr. Yang’s electoral maladies span the spectrum: He fumbled once it became clear that celebrity alone could not carry the day; he did not try hard enough to reach Black and Latino voters. His campaign was too media-driven, yet he never fully relinquished his Twitter account to more responsible hands. He failed to master the city’s intricacies, and did not turn on-the-ground energy into votes.“When you’re out in the streets and in the communities, and people are literally shouting at him, ‘I’m going to vote for you,’ what’s the step two?” asked Grace Meng, a congresswoman from Queens who endorsed Mr. Yang. “Step-one level of excitement isn’t enough.”In the initial stages of his campaign, it seemed like Mr. Yang was everywhere. While the rest of the field held virtual forums and fund-raisers, he was on the streets, touring Flushing, Queens, and Brownsville in Brooklyn, and visiting Hwa Yuan, a 54-year-old Chinatown restaurant struggling to survive the pandemic. He sat for interviews with Wolf Blitzer and “The View,” and won big-name endorsements from Representative Ritchie Torres of the Bronx, and Martin Luther King III.Mr. Yang, who declined to be interviewed for this article, vowed to deliver $2,000 a year in guaranteed cash to the city’s 500,000 poorest New Yorkers. It was far from the universal basic income plan that drove his presidential campaign, and he never clearly explained how he would pay for it, but it still forced some of his rivals to respond with cash relief plans of their own.At campaign events like the reopening of Coney Island, Mr. Yang was relentlessly positive.James Estrin/The New York TimesHe had to quarantine when a campaign staffer got Covid, and then isolate again when he got it himself. He suffered through a kidney stone. But little seemed like it could stop him, not even a series of gaffes.He suggested that New York should put a casino on Governors Island, a green respite in the harbor where casinos are illegal. He released a video of a local “bodega” that seemed to suggest to social media critics that he did not know what a bodega was. He incited the left when he suggested he would crack down on street vendors — many of them undocumented workers with few other options at their disposal.Mr. Yang, 46, also withstood ridicule after telling The New York Times how he spent much of the pandemic in his second home upstate. He noted the challenges of fulfilling his obligations as a CNN commentator from his apartment in Manhattan, explaining, “Can you imagine trying to have two kids on virtual school in a two-bedroom apartment, and then trying to do work yourself?” Many New Yorkers had no trouble imagining that at all.“I think we took a lot of cannons for a long time, some of it justifiable,” said Chris Coffey, one of Mr. Yang’s two campaign managers, who was speaking by phone from Governors Island, where the Yang campaign was having a postelection picnic whose location was intentionally ironic (and where there were in fact cannons). “It’s hard to know what causes the ship to eventually take on water. I still think most of it is the race just changed.”Mr. Yang’s nonstop campaign schedule did come to a halt when he had to isolate after testing positive for Covid-19. Sara Naomi Lewkowicz for The New York TimesTwo weeks in particular stood out to campaign supporters as the turning point in Mr. Yang’s fortunes. On May 10, Mr. Yang sent out a tweet that was drafted by a Jewish adviser, and vetted by Mr. Coffey. At the time, the Israeli army and Hamas were exchanging fire, a dramatic ratcheting up of tensions that killed civilians on both sides, but particularly Palestinians.“I’m standing with the people of Israel who are coming under bombardment attacks, and condemn the Hamas terrorists,” Mr. Yang said. “The people of NYC will always stand with our brothers and sisters in Israel who face down terrorism and persevere.”Nothing about the tweet was out of step with how New York politicians typically talk about Israel. The city is home to the largest Jewish population outside of Israel, and Mr. Adams had made a similar statement. But Mr. Yang has nearly two million Twitter followers, and his tweet drew attention from all sides.Mr. Yang received unwanted praise from Senator Ted Cruz of Texas and Stephen Miller, the Trump adviser, and unwanted condemnation from Representative Alexandria Ocasio-Cortez of New York, who said that Mr. Yang’s remarks, followed by his plan to attend a Muslim event in Queens, were “utterly shameful.”The episode led the campaign to tighten its process for reviewing urgent policy tweets, Mr. Coffey said, requiring that all of them get approval from both him and Sasha Neha Ahuja, Mr. Yang’s other campaign manager.On May 19, Mr. Yang demonstrated ignorance about the debt load of the Metropolitan Transportation Authority, whose subway and bus system he had proposed to take over from the state. The next day, he failed to understand a question about a controversial law that protected police disciplinary records; hours earlier, he had proposed creating homeless shelters for victims of domestic violence, even though New York City has operated such shelters for years.In the race’s last stages, Mr. Yang campaigned alongside Kathryn Garcia, and encouraged his followers to rank her second.Michelle V. Agins/The New York TimesIn retrospect, rival campaign aides said that Mr. Yang erred from the beginning by not expressing more humility and a hunger to learn the New York City political ropes from those who know them.Peter Brown, the chief strategist for Kathryn Garcia’s campaign, said he disagreed with the Yang campaign’s decision to release internal polling that at times conjured a sense of the near-inevitability of victory. Instead, Mr. Brown suggested that it would have been wiser to release a memo minimizing expectations, portraying Mr. Yang as an overachieving underdog who was going to have to work hard.Micah Lasher, the campaign manager for the city comptroller, Scott M. Stringer, made a similar point, and harkened back to Hillary Clinton’s run for the Senate.“Hillary Clinton came in 2000 and demonstrated a surprising humility and interest in learning, and there was a version of that that Yang could have done,” Mr. Lasher said. “Instead, they did the opposite: ‘We’re here, we are big, we are going to win.’ That was the beginning and end of their game plan.”By the end of the campaign, Mr. Yang’s camp had shifted yet again — the preternaturally upbeat Mr. Yang turned negative.Mr. Yang used a recent spate of anti-Asian attacks to push for more public safety measures, including getting people with untreated mental illness off the streets.Andrew Seng for The New York TimesAfter he spent months publicly asking Ms. Garcia to serve as his deputy in City Hall, her poll numbers rose and he started attacking her record as sanitation commissioner. He routinely suggested Mr. Adams lacked a moral compass. And he futilely tried to outflank Mr. Adams on crime.“Yes, mentally ill people have rights, but you know who else have rights? We do: the people and families of the city,” Mr. Yang said at the final debate. “We have the right to walk the street and not fear for our safety because a mentally ill person is going to lash out at us.”Mr. Yang was speaking from some personal experience. As an Asian American man, he was a member of a community that had been victim to a spike in hate crimes, some of them committed by New Yorkers with histories of mental illness. Polls had found that economic recovery and moving beyond Covid were no longer top of mind for voters, and Mr. Yang was diverging from his original message.“Our core issues faded not just from first to second, but to third,” said Eric Soufer, a senior adviser to the Yang campaign. “You can’t keep running a campaign based on the same thing, when the fundamentals change like that.”But some campaign staff members acknowledged that they became disillusioned by some of Mr. Yang’s shift in positions, and how they did not comport with the man who promised to be the anti-poverty mayor, who vowed to institute guaranteed income for poor New Yorkers and help establish a public bank.As the primary night results were released, Mr. Yang became the first mayoral candidate to concede.Gabriela Bhaskar/The New York Times“At the end, there wasn’t a clear, cogent argument of what he stood for that resonated,” said Ron Kim, a Queens assemblyman who endorsed Mr. Yang. “If I could go back, I would have encouraged him to stick with what he was known for, which was being an innovator, a person who can deliver out-of-the-box thinking on solutions for economic growth and jobs.”In the race’s last stages, Mr. Yang threw his support to Ms. Garcia, encouraging his supporters to rank her second. Though they campaigned together, she did not ask the same of her supporters; she said she had hoped to piggyback on Mr. Yang’s popularity in certain sectors of the city.Mr. Yang did perform well with heavily Asian communities in Queens like Elmhurst and Flushing, as well as in heavily Orthodox Jewish neighborhoods in Brooklyn, like Borough Park. He did not do nearly as well in Manhattan, his home borough, where he garnered 10 percent of the in-person vote; Ms. Garcia captured the most votes in that borough.“There were some tensions within the team where people would say, ‘Well, you can’t out-cop the cop,’” Mr. Yang said in an episode of his podcast that aired Monday.“For me,” he added, “both common sense and the numbers indicated that crime was going to be the number one issue.”And despite being the self-described ideas candidate, Mr. Yang did not have enough of them to entice voters.“As the person who was getting most of the attention, the race became a referendum on him,” said Stu Loeser, who advised the campaign of Ray McGuire, the former Citigroup executive. “And he proved himself to be a callow, unsubstantial, often dimwitted person.” More