From the start, there were things that were under Hillary Clinton’s control, and many, many things that never would be. She was a technocrat facing an America demanding revolution. She was a scarred but stalwart fighter in her third decade of battle, facing a new generation of enemies. Her instincts, oriented toward substantive debate, were in the words of one loyalist, “suboptimal” for a changing political scene in which voters were looking for attitude, not answers. When convinced she was right, she proved stubborn.

Yet there was potential for her and for history. No one hustled harder than Clinton, whose childhood Sunday-school lessons about the virtues of hard work and good deeds she had translated into a life in public service. She obsessed over details and demanded plans for everything, all the while being unfailingly kind to her allies and aides. And perhaps most appealing to the political professionals, she valued a well-oiled campaign machine and recruited many of the people who built the one Barack Obama used in his two winning elections. It seemed, as she readied her campaign launch, the dysfunction that bedeviled her 2008 run for the White House had been exorcised.

So hundreds of Democratic operatives uprooted their lives, from the top-ranking leaders in the party who moved to New York for positions in the high-stakes, low-pay headquarters to the idealistic 20-somethings who registered only vague memories of Clinton’s time as First Lady or even her 2008 campaign. Aides who had launched the Obama campaigns shared offices, while others traded West Wing perches for cramped spaces and roommates. It was never going to be sexy, but it didn’t have to be. They were this generation’s best and brightest, matched with a trailblazer who was poised to become the first woman to earn the Oval Office.

The campaign Clinton and her team built was a dramatic departure from the inspirational tours de force that twice elevated Obama to the White House. Without a mantle of change or a movement of hope, Clinton and her crew patiently worked to construct an unstoppable machine. It was at times laborious and often dispiriting. And in the end, it came up short against the populist phenomenon of Trump, who bet his entire campaign not on mechanics but on energy. He had the ability to electrify voters.

While the billionaire defined his side of the race by the fantastic and spectacular, Clinton kept her head down, frequently focused on priorities that would never make headlines or on the nuts and bolts that keep a campaign running. If Obama’s quants had pioneered the use of complex analytics to identify and attract voters, the Clinton operation used data sets to identify volunteers for the campaign that tried–and failed–to overcome an enthusiasm deficit.

There were moments of optimism. When Clinton was on, she was unstoppable. Her marathon, 11-hour testimony in October 2015 on the attacks on the U.S. outpost in Benghazi, Libya, was a shining moment that calmed Democrats’ nerves about her still uncertain nomination. Her three general-election debate performances sparked the imagination of skeptical crowds, especially younger voters. The Clinton campaign was wired to run circles around Trump’s operation in the states and was unquestionably far better prepared than Trump’s. For a time, it seemed those strengths might be enough to overcome the phenomenon of a former reality-TV star whose empty podium drew more coverage than her policy speeches–or a press corps whose dogged antagonism toward the Democrat left many Clinton staffers personally offended by what they saw as a double standard.

Still, there were warning signs. Her Democratic rival Bernie Sanders promised a revolution of his own and rallied young voters who resisted Clinton, with her policy prescriptions and merit-based candidacy. Her use of a private email server while she was Secretary of State dogged her endlessly, including at a precampaign press conference in a U.N. hallway that later proved too rosy and a late-campaign bombshell from the FBI that ticked ominously before proving a dud. She fought to keep paid Wall Street speeches on Bill Clinton’s schedule. In landlocked Iowa, she detailed plans for tackling Laotian land mines and in Libertarian-leaning New Hampshire effused about government-backed loans for Big Business. Aides grimaced and groaned–and then put online the video of the ill-timed land-mine chat as evidence of a heavyweight worthy of support. It worked in a way–Clinton made up for voters lost on the campaign trail with ones gained through social media. Her digital team called this evidence of an ability to clothe traditional politics in trappings of technology.

The eternal political reality remained, however: a machine can’t stop a movement, and America prefers a warrior over a wonk.

From the start, campaign manager Robby Mook knew he had challenges ahead of him. The boyish Columbia University graduate with a degree in the classics had been hired at 35 for the toughest job in politics. He shared Clinton’s unflinching belief that preparation can trump emotion. Everyone warned him that Clinton could be tough to crack and often had parochial preferences, like staying at her home in New York rather than camping out in swing states. She also insisted on beginning her campaign on a listening tour to hear voters speak about their concerns, even though her pollsters had binders of research that would have allowed her to skip that step. Aides made their displeasure clear to one another but knew that forcing Clinton to do something against her instinct was unlikely. It wasn’t until last June that Mook and friends were able to deliver the textbook, picture-perfect campaign launch on New York City’s Roosevelt Island.

Clinton was neither lazy nor lackadaisical. Once she settled on a plan, she worked harder than anyone to execute it, a discipline acquired during a summer away from Yale Law School when she campaigned out of an empty storefront on West Sixth Street in Austin for George McGovern’s hapless 1972 White House bid. “I had a small cubicle that I rarely occupied because I spent most of my time in the field,” Clinton wrote in her memoir. Like her staff, she reveled in the grind. But that diligent focus produced huge blind spots away from the field; Clinton never visited Wisconsin during the general-election campaign, and on Nov. 8, the state tipped in Trump’s favor with an ease that caught the Democrat flat-footed.

Some of the volunteers doing the kind of fieldwork Hillary Clinton had done 44 years earlier sensed the problem. “I’d feel a lot better if she was winning by 20 points,” said Andrew Silvia, a 34-year-old city engineer from Attleboro, Mass., who took his first turn as a volunteer in the New Hampshire offices the weekend before Election Day. He was part of the army that knocked on more than 415,000 voters doors in the state that weekend alone. But it didn’t stem Trump’s surging tide.

The campaign’s rough early going might have foreshadowed the stunning final hours. Sanders’ unexpected primary challenge gave voice to a youth-driven populist fury that sought a revolution against powerful elites–in short, people like Clinton. She would prove her mettle with voters, but the victories tended to be difficult, costly and uncertain, starting with lead-off Iowa, where her victory was razor-thin. As Clinton boarded her middle-of-the-night flight, the staff left behind to tidy up found themselves with a six-pack of Miller Lite. The room-temperature tallboys were, like the campaign, serviceable and a bit tepid, but they got the job done.

Things didn’t get easier in New Hampshire, the state that gave Clinton her second chance in 2008. Mook met with the veteran activists from the previous campaign who volunteered to stay away from her small events in order to give newcomers a chance to size up the candidate. Even so, Sanders, from neighboring Vermont, crushed her almost 2 to 1.

As the primaries progressed, the emotional seesaw swung higher and sank lower. Blue collar voters in Michigan bought Sanders’ antitrade rhetoric, dealing Clinton such a blow that the March 8 primary was almost universally regarded as the worst day of the campaign–that is, until Nov. 8. In the primary, public polls showed her ahead while the data team back at headquarters was seeing entirely different numbers. Clinton lost the state by 1.5 percentage points to Sanders and by an even smaller margin to Trump.

But if the primaries were a grind, Clinton’s confidence never wavered. Aides had warned her early on that there would be losses–as many as three of the first four states could go to Sanders, according to one briefing memo. Mook mobilized his team to hire staff for the fall campaign even before the nomination was sewn up. “That will be a tell to everyone that we are moving on to the general,” Mook told his cabinet. The candidate, who was open about her lackluster skills at political theatrics, had a veritable passion for preparation.

Clinton’s team projected confidence for good reason. They had impressive data on every voter they needed to turn out, yet their statistical models, much like public polls, were wrong. They used Clinton’s star turn at the first debate to generate enormous energy. The campaign challenged its satellites in the states to make new recruitment records. Most did, but North Carolina had the most impressive results: its previous record for one-day recruitment was 3,000 shifts. It set a goal of 4,000 shifts and signed up 13,000 shifts in the 24 hours after Clinton won the first debate.

On the last weekend of October, 23-year-old Elizabeth Nadler filled one of those shifts. A recent graduate of Duke University, she worked in the school’s theater department as an assistant while volunteering for the Clinton campaign at least 20 hours a week in the Durham, N.C., office. “We’re all in this together,” she said on the Saturday that TIME caught up with her at the campaign offices, where newcomers got a crash course in campaigns and were then sent out with lists of doors to knock on and questions to ask. The movement vibe that Clinton had never been able to spark was, finally, emerging, largely because Clinton had stood toe to toe with Trump for three debates and never flinched.

By the time Election Day arrived, Clinton had swayed the voting public. Exit polls found 63% of those casting ballots said Trump lacked the temperament to do the job, and 60% said he was unqualified. As those findings were coming in, Nadler was working one last shift door to door. “There’s still time to knock on doors. This is going to be close,” she said. Like supporters at campaign headquarters in Brooklyn, she was expecting the night to end with chants of Madam President.

So had Clinton’s team. It just didn’t work out that way. It is hard to overstate how shell-shocked the campaign felt as that realization settled in on election night. Many senior aides had been openly talking about whether they had the energy to go straight from the campaign into the White House. Some spoke of cashing in for a few years in the private sector so they could afford the terrible pay of government work. There was watercooler chatter about who would get what office in the West Wing and more serious discussions of moving much of the machinery from Brooklyn to the Democratic National Committee in D.C. to establish a permanent campaign. The data told them they were on solid ground. The voters told them otherwise. “I know how disappointed you feel because I feel it too,” Clinton said the morning after. “This is painful, and it will be for a long time.”

–With reporting by SAM FRIZELL and CHARLOTTE ALTER/NEW YORK

This appears in the November 21, 2016 issue of TIME.

Get our Politics Newsletter. The headlines out of Washington never seem to slow. Subscribe to The D.C. Brief to make sense of what matters most. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

Write to Philip Elliott at philip.elliott@time.com.