DES MOINES — Pete Buttigieg's top advisers realized something was happening when an editor in CNN's green room showed them the spike in the network's social media tracking.

On the second Sunday in March, the long-shot presidential candidate, who was then a 37-year-old mayor of a city of about 100,000 people, had taken the stage for a cable news town hall as little more than a curiosity without a suit coat. He left as a contender.

“It was like night and day,” Lis Smith, his senior adviser, said of what happened next.

Invitations soon flooded in for more fundraisers and television appearances, even on shows such as Ellen DeGeneres’s, where he hadn’t gotten booked. Heavy hitters from the Democratic fundraising world signed up with his campaign on the spot.

“ ‘Did you see that?’ ” David Jacobson, a former ambassador to Canada and a bundler for President Barack Obama, remembers asking his wife that night. “Because it wasn’t just good. It was magnificent.”

When Buttigieg met a few weeks later with the men who would become his television consultants, veterans of Obama’s 2008 victory, they came bearing an outlandish prediction.

“The first thing I said to him was, ‘You are going to win Iowa,’ ” recalls John Del Cecato, one of those admakers.

The outcome would be far messier than anyone expected, mired in chaos and uncertainty in the wake of the state party’s counting meltdown — so much so that Democratic National Committee Chairman Tom Perez on Thursday called on the state party to begin a “recanvass” of the caucus results.

But by the time most of the results had been tabulated, it was clear that the young former small-city mayor was the biggest surprise of the Iowa campaign — outpacing a pack of far more established and seasoned politicians.

The youngest candidate in the race joined the oldest, 78-year-old Sen. Bernie Sanders of Vermont, at the top of the heap, with both men declaring victory as results were still being counted. With 100 percent of precincts reporting Thursday night, Buttigieg held a narrow lead of 26.2 percent in state delegate equivalents, the traditional metric by which an Iowa winner has been determined. Sanders had 26.1 percent and held a slight lead in the popular vote. And both men won bragging rights, as they are expected to draw roughly the same number of Iowa delegates to the national nominating convention.

“Who inches ahead in the end is meaningless,” Sanders said Thursday in New Hampshire.

Despite the embarrassing end to its 2020 caucuses, Iowa nonetheless provided an unexpected — and potentially transformative — twist to what has been a consistently unpredictable Democratic nomination fight. More than two dozen candidates, including a former vice president, seven senators and a businessman who boasted of being “an Asian guy good at math,” had thrown themselves for months before a traumatized and nervous Democratic Party.

They stood on countertops, braved snowstorms and paraded meat on a stick, all in the hope of wooing a small fraction of Iowa’s voters — probably fewer than 200,000 out of more than 2 million voters — to huddle in groups in conference rooms and high school gymnasiums.

By the end, former vice president Joe Biden, the leader in national polling, found himself humbled in fourth place by a process that exposed his campaign’s dysfunctional organizing and muted grass-roots energy — a “gut punch,” as he put it this week.

And Sen. Elizabeth Warren (Mass.), the third-place finisher in the state, who branded herself the “I have a plan for that” candidate, found her hopes diminished by an inability to settle on a health-care plan that satisfied both sides of her coalition.

This account of the tumultuous year of campaigning that culminated this week in Iowa is based on interviews with more than 25 advisers to the top four campaigns. Some spoke on the condition of anonymity to be more frank about internal deliberations and struggles.

Each of the top four contenders held a polling lead at one point in the state, where uncertainty and a desire to defeat President Trump were the dominant feelings among caucus-goers.

The outcome came down to organization, timing, luck and one unexpected misfortune.

'Bernie needs us'

Sanders didn’t like to speak from a chair. That was the first sign of trouble.

“I’m going to sit down here,” he said onstage at a Las Vegas restaurant in early October. “It’s been a long day.”

Minutes later in a car, his staff asked what was wrong. He said he was feeling a little sick. Not pain, exactly, just a tightness in his chest. The nearest urgent care center popped up on Google Maps, but the 78-year-old senator who made public health care for all his signature demand was turned away because there were too many other patients.

Another clinic put him in an ambulance to a hospital, where Sanders handed off his wedding ring before a surgeon placed two stents in his artery. The campaign suspended its ads from the Iowa airwaves and stopped emailing supporters for money. Some staff members worried that they would need to close up shop.

Nobody predicted what happened next.

A few days after the heart attack, before it was clear that Sanders would recover, Pete D’Alessandro, his Iowa director, found something unusual at a regional office in Des Moines near his home. The candidate was hospitalized, but the number of volunteers working the phones had roughly doubled.

That weekend, Rep. Ro Khanna (Calif.), a Sanders campaign co-chairman, discovered a similar scene when he flew to the state — big crowds, even without the candidate, many with stories about their own health scares. “Solidarity,” Khanna concluded.

Others soon noticed a deeper shift among Sanders supporters. “You start talking to people and generally the demeanor was, ‘We have got to pick it up for him now,’ ” D’Alessandro said. “It was almost like what it would have felt like if you were working for Robert Kennedy and somebody had tackled Sirhan Sirhan.”

Far from Iowa, among the sprawling community of liberal activists and leaders, a shift was taking place. Those who had spent much of the year torn between Sanders and Warren, the two liberal lions of the campaign, began to add a new calculation to their considerations.

“Just like when we get close to losing a loved one or when you do lose a loved one,” said Evan Weber, the political director of the Sunrise Movement, which would eventually endorse Sanders by a margin of more than 4 to 1. “It makes you stop and really value the things you had.”

Rep. Alexandria Ocasio-Cortez (D-N.Y.), the public face of a new generation of activists, had been meeting with both senators privately as they sought her endorsement — Warren over a lunch in Washington to talk policy and Sanders in Burlington for dinner and brunch to discuss what the movement might be.

When she heard he was in the hospital, she moved fast to endorse, a decisive moment, rival campaign strategists said, with her freshman colleagues Ilhan Omar (Minn.) and Rashida Tlaib (Mich.). Sanders had stopped answering all his calls in the hospital, so an adviser had to patch Ocasio-Cortez through to his bedside two days after the surgery.

“Bernie needs us, and needs us now,” she told an aide at the time.

Up until then, the campaign had been plodding along. Sanders’s decision to run had never been a sure thing. He entered the race in March, with crowded events in Brooklyn and Chicago where he received rock star receptions. But from there, the campaign sputtered, not quite sure how to recapture the magic of 2016 in a bigger and more fluid field. In late April, Biden joined the race, giving Sanders a new problem.

During a private conversation in May, Jeff Weaver, a senior adviser who had managed Sanders’s 2016 effort, successfully pleaded with the candidate to restart his polling program, which had been dormant in the opening months of the campaign, save for some general election data it released publicly.

Fresh rounds commenced in the summer, and the new numbers informed the campaign’s aggressive ad strategy and sharpened focus on economic issues, said two people with knowledge of the situation.

By October, with Sanders still recovering, his team was working on something that could be even more consequential: a rally with Ocasio-Cortez in New York’s Queensbridge Park — a sprawling patch of green in the shadow of the Queensboro Bridge. He and his aides had written a new line, which would become a staple of her remarks.

“Find someone you don’t know — maybe somebody who doesn’t look like you,” Sanders told the crowd of about 20,000. “My question now for you is: Are you willing to fight for that person as hard as you fight for yourself?”

That was the core of the Sanders strategy. In Iowa, his team leaned heavily on a smartphone app that allowed supporters to share information about everyone they knew, to help build the campaign’s voter file and improve its targeting.

“You now have a way to look up people who you know, in your precinct, in your Zip code. You can sort it by age, you can sort it by a variety of things. You can also look up individuals,” a Sanders organizer told supporters in Des Moines’s East Village in December. “When we mark our friends or family members, our neighbors as Bernie’s supporters or otherwise, that is super valuable information.”

The internal numbers started moving as fall turned to winter. In early November, in Council Bluffs, D’Alessandro watched as voters carrying Sanders signs started streaming out of the venue after Ocasio-Cortez’s introduction. It didn’t matter that the senator was still speaking. They had come to see her.

“All of a sudden, we started that expansion of our universe,” he said.

'Extreme derision'

The dynamics of the Iowa campaign that Buttigieg and Sanders would exploit could be traced back months before anyone publicly declared their intention to run, as would-be candidates and their aides tried to decipher how the nation — and the Democratic Party — had changed since Trump’s shocking win over Hillary Clinton.

In the final months of 2018, Biden gathered regularly with his inner circle in the basement office of his $4 million rented home along the Potomac River to put him through the paces.

Some proposed that he come out of the gate with a “more aggressively left-leaning posture,” said one aide who attended the meeting. They warned him that Medicare-for-all had become the flavor of the year in Democratic policy circles. They explained the dangerous vicissitudes of Twitter and its hold on the political press.

“We were very clear-eyed in those conversations that we were going to be met with extreme derision,” said Kate Bedingfield, who would go on to become his deputy campaign manager.

From the beginning, Biden and his top aides rejected the idea that Sanders’s vision had legs. That wasn’t the party he knew or the country he had helped lead. He didn’t believe the rise of Trump had changed either.

Ultimately, they argued, the campaign would turn on issues more fundamental than political ideology or populism. The country needed healing and a hug from a man who had been through more than most and understood.

“We have a candidate who knows who he is,” campaign manager Greg Schultz said. “The country wants to come together.”

A campaign that began amid complaints by women who said that Biden’s physical manner made them uncomfortable closed out the year with an impeachment scandal sparked by Trump’s desire to highlight his son Hunter Biden’s work in Ukraine. Yet his polling was resilient.

“Democrats love Joe Biden,” said one pollster, who spoke on the condition of anonymity because he was talking about another campaign. “No one is rooting for him to fail.”

The script that Biden’s brain trust crafted leaned heavily on a legacy that much of the country already knew — words such as “malarkey,” verbal tics such as “seriously, folks” and mottos about rebuilding the backbone of the nation that had been prepped for a potential 2016 presidential campaign he never ran.

But the team ultimately decided to break away from the old formula.

Mark Putnam, a prominent Democratic Party admaker, was brought in to create an introductory spot for Biden anchored in his oft-told story about his ­working-class upbringing, shooting footage of the former vice president as he visited his childhood home in Scranton, Pa. The video, which was not released, was shelved by Mike Donilon, Biden’s top strategist, to make way for the new rationale.

If Biden was the healer, they would call out the disease. The campaign would start with the heart of the matter: Trump’s equivocating response to the march of white nationalists in Charlottesville in August 2017.

Warren has approached the same question from the opposite direction. The disease, she thought, was not Trump, but decades of policy choices in Washington that had made voters look to a demagogic politician like him in the first place.

By the time Warren went public with her presidential ambition in the final hours of 2018, she had been an elected official in Washington for less than six years, and had been urged to run for president for most of that time.

Liberal activists had pleaded with her after the 2012 election. Joe Rospars, the Obama campaign’s digital strategist who would become her chief strategist, wrote an unsolicited memo predicting that she would raise $100 million in the first months of a primary run against Clinton.

Said Zephyr Teachout, an organizer on Howard Dean’s 2004 presidential campaign who met with Warren in person: “I practiced and practiced this speech to convince her. My pitch was, ‘There is a sleeping giant awakening in America.’ ”

Warren was sold on the thesis but not her next move, until after Trump won the White House. Two days after the 2016 election, Warren delivered a speech signaling her change of heart. She chastised her party for not addressing the country’s economic pain.

“President-elect Trump spoke to these issues,” she said, placing herself in the middle of the debate. “. . . The time for ignoring the American people is over.”

But the 2016 election had changed more than just the occupant in the White House. Once a congressional gadfly, Sanders had earned a solid claim on the liberal populist crown. Even Teachout, by the end of 2019, would endorse him.

Warren placed a bet anyway that she could win his supporters, even as some of her advisers doubted his determination to run again. She would broaden the coalition to include the college-educated part of the Democratic Party. She called herself a capitalist, not a democratic socialist. She promised “big structural change,” not a revolution.

Warren would have to compete for two sets of voters at once, and she planned to out-hustle everyone.

A couple of days before New Year’s Day 2019, as her exploratory committee prepared to announce her bid, top staff members huddled in Boston to finalize a plan to immediately call or text anyone from the first four states to hold nominating contests who signed up on the website or donated after her video went live.

By the time Warren landed in Iowa five days later, strangers who had become volunteers were directing traffic in the parking lot of a Council Bluffs bowling alley.

She chose not to hire a campaign pollster and television ad consultant, and told a pair of top fundraisers that she would no longer ask the wealthy for money. The Iowa field operation she built quickly became known as the gold standard, with staff members setting up shop early in far-flung parts of the state, including deeply red rural areas.

By the end of the summer, there was a growing consensus that she was in a strong position to win Iowa. Biden’s campaign operation in the state was widely considered to be in disarray. Buttigieg had only just begun to announce plans to open offices and introduce himself to voters. And there were doubts that Sanders, the 2016 runner-up, could recapture the magic of his last run.

New realities

Before the CNN town hall gathering, Buttigieg’s team was not sure whether he would even get the 65,000 donors he needed to qualify for the first candidate debate. Less than three months later, he would report nearly $25 million in donations, more than anyone else in the field in the second quarter.

The pivot also brought veteran talent to a campaign that until then had been almost entirely run by people younger than 40. If Warren was trying to reinvent campaigns by eschewing polling and television consultants, Buttigieg embraced the old ways.

He hired Obama’s former polling firm, Obama’s former television ad team and a suite of other Obama veterans. Unlike Obama, who had three years to plan a national campaign after his 2004 Democratic National Convention speech thrust him onto the national political stage when he was still a Senate candidate, Buttigieg would try to put it together in four months.

Because so few voters knew Buttigieg, the campaign’s leaders invested in research about how the Democratic Party was feeling about politics and the country. What they found gave them hope, both for Buttigieg’s path in Iowa and New Hampshire, and for bringing down Warren.

A portion of the party had been electrified by Sanders, but of the rest, there was an exhaustion at the vitriol. It was a message that echoed in Biden’s research.

More important, they found that among those who wanted Medicare-for-all, many could live with a policy plan that got you part of the way there. The reverse was not true among opponents, who reacted strongly to the idea of losing their private insurance.

With suddenly deep pockets, Buttigieg committed himself entirely to the state. His team tried to make the biggest shows of force at each of the major organizing events, went up early and big with television ads, and opened more offices in the state than any of his competitors.

Democrats in the state began to take him seriously when his staff mistakenly scheduled a rally on Oct. 12 at Roosevelt High School in Des Moines, at the same time as a major Iowa Hawkeyes football game. During the big game in bad weather, more than 700 people showed up and stood for hours in freezing temperatures and drizzle to see him speak.

As Buttigieg moved in the summer to restart his campaign, the strains of Warren’s big-tent strategy were showing. She had begun the race calling Medicare-for-all an end goal, without committing to a specific path to get there.

In the spring, liberal groups and activists had been privately expressing frustration about her public position. To quiet those concerns, she shocked many in the party by shifting positions in Miami at the first candidate debate.

“I’m with Bernie,” she said.

Before long, the consequences of that decision began popping up on door knocks around Iowa, said a person familiar with internal campaign responses in the state. Many with private health insurance were worried.

Warren’s campaign had delayed coming out with a health-care plan, and now the candidate who campaigned on her policy expertise could not answer basic questions about whether her version of Medicare-for-all would raise taxes on the middle class.

Her rivals Biden, Buttigieg and Sen. Amy Klobuchar (Minn.) accused her of acting like a typical politician and not being direct with voters. Her reputation for competency and authenticity, which had been the bedrock of her rise through the polls, had been damaged. Her polling began to slouch in Iowa.

Biden, meanwhile, was quickly discovering that there was a difference between winning public opinion and winning party energy. The Iowa caucuses, which demanded the devotion to leave home for hours on a Monday night, required the latter.

That reality hit home for campaign staff members at the Liberty and Justice dinner in early November, the biggest single organizing event before the caucuses. At a half-full predinner rally, Biden staff could be seen holding thick handfuls of tickets that they were struggling to give away. Inside the arena, at the last minute, they removed boxes of inflatable noisemakers that read “Beat Him Like a Drum” from the four sections of seats they had reserved but were unable to fill.

The campaign tried to fill the seats with groups that had been bused in. One bus was filled with kids from a Baptist church who Karen Sievers, vice chair of the Guthrie County Democratic Party, said didn’t appear to “even know why they are there.”

“I remember being on the floor of the arena and looking around,” another Iowa Democratic activist said. “To have that kind of showing for a beloved former vice president, his own campaign failed him. And he had to know it.”

Later that month, a group of Biden supporters appealed to the campaign and even the candidate himself, urging him to pursue a more robust schedule of smaller, more personal events that would allow him to connect with state Democrats and put to rest questions about the 77-year-old’s age and agility.

“I wouldn’t call it a ‘come to Jesus’ moment, but that’s what it was,” one longtime Iowa supporter said, who spoke on the condition of anonymity so as not to anger the campaign.

Former Iowa governor Tom Vilsack (D) was one who had been arguing since the spring that Biden needed to truly commit to the state, especially in rural areas. A few weeks later, he would endorse Biden, joining his wife, Christie, former senator John F. Kerry (Mass.), and congresswomen Abby Finkenauer and Cindy Axne, both Iowa Democrats.

A super PAC the Biden campaign had blessed in October provided the air cover his own coffers could not afford, pushing back against the $10 million in anti-Biden spending that the Trump campaign had approved nationally to tar Biden and defend against impeachment.

Biden even imported Democrats of color from other parts of the country who traveled across the state as part of a “We Know Joe” bus tour to woo undecided Iowans, who have been especially outspoken about how their choice in the caucus might play in battleground states.

But holes in the campaign remained in the final months. When Biden’s wife, Jill Biden, toured western Iowa in mid-January, less than a month before the caucuses, she was introduced in Audubon by an organizer who said it was his first week on the job.

In Dubuque, where the candidate’s sister Valerie Biden Owens held a private meeting with a group of undecided voters last week, one attendee, who spoke on the condition of anonymity so as not to embarrass the local Biden organizers, said she was still undecided in the race in part because of questions she had about Biden’s ground game.

During the summer, the woman said, she had offered to volunteer and make phone calls on Biden’s behalf.

“When I finally found the organizer, he said he would get back to me, but I never heard a thing,” she said. “It made me wonder how committed Joe and his campaign were.”

As the caucuses began across the state, it became clear that she was not alone.

Dueling victory declarations

The year of campaigning came down to the final night. Television networks carried live images of caucus meetings, but as the night wore on, it became increasingly clear that something unusual was happening.

Unlike a typical election, where ballot choices are secret, the various campaigns received real-time reports of turnout and preference from the state’s 1,681 precincts. The numbers they reported back to Buttigieg in his suite at a downtown Des Moines Marriott cheered everyone in the room. But the state party was unable to collate the results.

The political wordsmith with degrees from Oxford and Harvard needed a win in Iowa to propel his campaign forward, so he decided to play a word game: He would declare himself “victorious” without defining what victory meant. His staff uniformly agreed, even though they knew he still might not finish first in the delegate count.

“It means victorious over a lot of things — victorious because a year ago, it was just four staffers, victorious in terms of overperforming the expectations, and victorious in that we beat a crop of senators and a former vice president,” said one of the advisers in the room.

A few moments later, Buttigieg appeared onstage, a 38-year-old openly gay former mayor from a small city in Indiana trying to convince the country it was really happening.

“Tonight an impossible hope became an undeniable reality,” he declared.

The final result, however, was still anything but certain.

“When 6,000 more people come out for you in an election than your nearest opponent,” Sanders said three days later in New Hampshire, “we here in northern New England call that a victory.”