Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

WASHINGTON — Less than two weeks before Election Day, Hillary Clinton held a clear lead in the polls and it looked like her campaign was trying to run up the score — just as the race was about to turn upside down.

At 12:37 p.m. ET on Friday, Oct. 28 — with 12 days left in the election — the campaign blasted out an advisory to reporters announcing that the former secretary of state would be campaigning in reliably Republican Arizona, a move that suggested her team was gunning to compete in states well beyond the battlegrounds they needed for victory against GOP nominee Donald Trump.

They had every right to be confident.

The RealClearPolitics polling average from the day before showed Clinton leading Trump nationally by nearly six points (for perspective, Barack Obama beat Mitt Romney by four points in 2012). State polls had Clinton ahead in key battlegrounds like Pennsylvania and North Carolina. Even the data team doing analytics for the Trump campaign was telling reporters that, as of Oct. 27, they had just a 15 percent chance of winning.

All this was happening while early voting was taking place in states across the country.

In retrospect, however, the race was never as stable as it appeared. A contest featuring the two most unpopular candidates in modern presidential campaign history made the political terrain unstable — and more susceptible to sudden shifts.

And the ground began to move under the Clinton team’s feet just 20 minutes after its Arizona announcement, with a tweet from Rep. Jason Chaffetz, R-Utah, the chairman of the House Oversight and Government Reform Committee, who said the FBI was looking at Clinton’s emails — again.

"FBI Dir just informed me, 'The FBI has learned of the existence of emails that appear to be pertinent to the investigation.' Case reopened."

FBI Dir just informed me, "The FBI has learned of the existence of emails that appear to be pertinent to the investigation." Case reopened — Jason Chaffetz (@jasoninthehouse) October 28, 2016

Clinton and her team were suddenly on defense, and would remain there for the rest of the race. It was a true October surprise.

In the nine months since the election, political observers have pointed to various reasons why Hillary Clinton lost and Donald Trump won: FBI Director James Comey’s intervention; Russia and WikiLeaks; Clinton’s failure to campaign in Wisconsin; African-Americans who didn’t turn out as strongly as they did for Obama; and Trump’s strong performance among working-class white voters in the Rust Belt.

But the real tale of 2016 is how the final 12 days of the election turned a race that seemed out of reach on Oct. 27 into an upset decided by a total of 80,000 votes in three states. To tell that story, NBC News interviewed nearly a dozen top Clinton and Trump operatives for their insight and perspective. Both sides agreed that the underlying volatility of the race, combined with the way the final days unfolded, produced a most unexpected result.

"Unlike 2012 or 2008, there was a ton of instability in this race," said Navin Nayak, the Clinton campaign’s director of opinion research. "If you were the person dominating the news, you went down."

Indeed, Clinton’s lead had expanded during rough news cycles about Trump (the Khan family, the debates, the infamous "Access Hollywood" tape), and it shrank during rough news cycles about her (the Clinton Foundation, the 9/11 fainting spell, Comey’s Oct. 28 letter).

And that made every day count down the home stretch.

"I’ve always said, 'God is looking out for us' when Election Day was so much later than usual — Nov. 8th, not Nov. 4th, not Nov. 3rd," said Kellyanne Conway, who served as Trump’s campaign manager and now works in his administration. "It really helped to have that [extra] week."

Even the Clinton camp’s Arizona announcement that Friday was more about running out the clock — by giving a hungry press corps something to cover — than a genuine effort to run up the score, according to multiple Clinton campaign officials interviewed for this article.

They knew the race was far from over.

"We were vulnerable to an October surprise," said Brian Fallon, the Clinton campaign’s national press secretary. "We were living high on the hog of the 'Access Hollywood' tape," he added in reference to their lead in the polls.

Here’s a look at how the final 12 days changed the race:

Oct. 28: "The biggest political scandal since Watergate"

RealClearPolitics national polling average: Clinton +4.6 percent/FiveThirtyEight forecast: Clinton 81.5 percent chance to win

The first 27 days of October couldn’t have gone better for Clinton — or worse for Trump.

Clinton bested her Republican rival in all three presidential debates, according to snap polls. The "Access Hollywood" tape, in which Trump was caught boasting that he could do anything to women (like "grab 'em by the p***y"), had his campaign in damage-control mode. And it seemed that a different woman each day was accusing Trump of inappropriate behavior.

By mid-October, Clinton’s lead in the RealClearPolitics average of national polls had jumped to seven points — the same as Obama’s winning margin against John McCain in 2008. And an NBC News/Wall Street Journal/Marist poll of Pennsylvania showed Clinton ahead of Trump by double digits in that all-important state.

But that good run for Clinton ended on Friday, Oct. 28, as her 7-point advantage in the RealClear average shrank below 5 points.

Comey informed Congress that his agency had found emails in an unrelated case — a probe into former Rep. Anthony Weiner, D-N.Y., then-husband to Clinton aide Huma Abedin — which appeared "pertinent" to the investigation into Clinton’s personal email server. And he said the FBI was reviewing them.

Strikingly, Comey’s announcement was vague.

"Although the FBI cannot yet assess whether or not this material may be significant, and I cannot predict how long it will take us to complete this additional work, I believe it is important to update your Committees about our efforts in light of my previous testimony," Comey said in his letter.

Supporters of Republican presidential candidate Donald Trump cheer during a campaign rally, Wednesday, Nov. 2, 2016, in Pensacola, Fla. Evan Vucci / AP

Trump seized on the development, which he used to resurrect the months-long controversy over Clinton’s emails and private server.

"They are reopening the case into her criminal and illegal conduct that threatens the security of the United States of America," Trump said on the campaign trail in New Hampshire less than an hour after the news broke. "Hillary Clinton's corruption is on a scale we have never seen before. We must not let her take her criminal scheme into the Oval Office."

"The investigation is the biggest political scandal since Watergate, and it's everybody's hope that justice at last can be delivered. The FBI would never have reopened this case at this time unless it were a most egregious criminal offense" — candidate Donald Trump in Iowa.

He would repeat the thrust of this message against Clinton over the next 11 days, and his supporters would respond with "lock her up" chants. "She'll be under investigation for years. She'll be with trials. Our country, we have to get back to work," Trump said on Nov. 4 in New Hampshire.

"If she were to win this election, it would create an unprecedented constitutional crisis. In that situation, we could very well have a sitting president under felony indictment and ultimately a criminal trial," he said the next day in Nevada.

That became Trump’s closing argument — Watergate, endless investigations, criminal activities and an inability to govern.

Of course, what voters didn’t know until after the election: The FBI, for months, had been investigating the Trump campaign’s ties with Russia.

Oct. 31: "FBI searches emails!"

RealClearPolitics national polling average: Clinton +3.1 percent/FiveThirtyEight forecast: Clinton 75.2 percent chance to win

The Comey story wasn’t just about how Trump seized on it; it also was about how it was covered.

On October 31, three days after the FBI director’s letter to Congress, Comey continued to dominate headlines and evening newscasts.

"Clinton Works to Keep Trump and Emails at Bay," said The New York Times

"Get ready for four more years of Clinton scandals," was the headline for conservative columnist Marc Thiessen in The Washington Post

"Is new scandal just like the old scandals? Controversies haven't swayed voters much in the Clinton-Trump race. Email inquiry is the latest test," The Los Angeles Times said

"Email Review Underway," was the lead story on NBC’s "Nightly News"

"FBI Searches Emails," was the top news that night on ABC

"FBI Investigation," said CBS

Nearly half of the lead stories on the three broadcast network's evening newscasts from Oct. 28 to Nov. 7 were about Clinton’s emails.

Nine months after the election, top officials who worked for both the Clinton and Trump campaigns believe Comey’s intervention — and its aftermath — affected the race.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Multiple Trump aides said they gained ground on Clinton after the third presidential debate when the GOP nominee focused on abortion and the Supreme Court, bringing conservative voters back into the fold. They also said they benefited from news stories about rising Obamacare premiums and a sharper campaign message from Trump himself.

Comey, they said, added to a snowball that was already moving down the mountainside.

"It certainly had an effect," said Matt Oczkowski, who directed Trump’s analytics team. "Comey brought these voters out of the woodwork. People had a reason to vote against Clinton."

Conway, Trump’s campaign manager, had a slightly different take.

"The Comey letter may have been mildly helpful, but it did not lead to 306 electoral votes," she said. "That was baked in the cake earlier on."

"We saw [Clinton] was stuck in neutral, her floor and ceiling were dangerously close together in these key states" — then-Trump campaign manager Kellyanne Conway.

But the Clinton camp believes Comey’s intervention was much more significant.

"In the last two weeks, it was the only jolt to the system that occurred," said Oren Shur, the Clinton campaign’s director of paid media. "We recognized at the time that it was impactful. We didn’t recognize at the time that it was determinative."

Elections number-cruncher Nate Silver of the website FiveThirtyEight agrees.

"At a maximum, it might have shifted the race by 3 or 4 percentage points toward Donald Trump, swinging Michigan, Pennsylvania, Wisconsin and Florida to him," Silver wrote. "At a minimum, its impact might have been only a percentage point or so. Still, because Clinton lost Michigan, Pennsylvania and Wisconsin by less than 1 point, the letter was probably enough to change the outcome of the Electoral College."

The New York Times’ Nate Cohn has been more skeptical that Comey’s announcement cost Clinton the election, pointing out that her poll numbers had been declining before Oct. 28: "[I]t’s now clear that Mrs. Clinton was weaker heading into Oct. 28 than was understood at the time. Several other polls were conducted over the same period that showed Mr. Trump gaining quickly on Mrs. Clinton in the days ahead of the Comey letter."

In May, the American Association for Public Opinion Research concluded that the evidence Comey tipped the election to Trump is, at best, mixed. "[T]he Comey letter had an immediate, negative impact for Clinton on the order of 2 percentage points. The apparent impact did not last, as support for Clinton tended to tick up in the days just prior to the election," the association wrote.

But the way Clinton and her top campaign officials see it, a different president would be sitting in the Oval Office had the race ended two weeks earlier.

"If the election had been on Oct. 27, I would be your president," Clinton said last spring.

Nov. 2: "Stay on point, Donald. Stay on point"

RealClearPolitics national polling average: Clinton +1.7 percent/FiveThirtyEight forecast: Clinton 67.7 percent chance to win

Comey wasn’t the only surprise of the final two weeks of the campaign. The other was how Trump, uncharacteristically, stayed on message.

He was no longer attacking former Miss Universe Alicia Machado, criticizing a Mexican-American judge, or asking: "Russia, if you're listening, I hope you're able to find the 30,000 emails that are missing" — which he had said in what turned out to be his final news conference of the campaign, on July 27.

"He was remarkably disciplined down the home stretch. You could tell there was a light that went on — that we’re going to win this thing" — a top Trump campaign communications official.

"We are going to win the White House, gonna win it," Trump said in Pensacola, Florida, on Nov. 2. "Just —we've gotta be nice and cool, nice and cool. Right? Stay on point, Donald, stay on point. No sidetracks, Donald. Nice and easy."

Indeed, Trump fired off 138 tweets and retweets in the final 12 days of the contest, and none were controversial — which allowed his campaign to keep the focus on Clinton, and away from its candidate.

Meanwhile, on the same day Trump was telling himself to "stay on point" in Florida, Clinton made that campaign stop in Arizona.

Democratic presidential candidate Hillary Clinton watches the World Series baseball game between the Chicago Cub and the Cleveland Indians after her final campaign rally of the day at Arizona State University in Tempe, Ariz., Wednesday, Nov. 2, 2016. Andrew Harnik / AP

"This state is in play for the first time in years. Arizona has only voted for a Democrat for president once since 1948, and that was my husband in 1996," she told 15,000 voters in Tempe.

In fact, multiple Clinton campaign officials said in post-election interviews that the Arizona trip was intended to regain a sense of momentum after the final debate on Oct. 19, not as a real play to win the state.

Clinton campaign officials were also thinking about proposing a fourth presidential debate, and they had even floated the news that Clinton was considering Vice President Joe Biden as her secretary of state — anything to change the subject.

"What had concerned me greatly after the third debate was being [adrift] at sea. No moorings, no bearings, nothing to anchor yourself. The danger zone for us was always when there was nothing else going on in the race," said Jennifer Palmieri, the Clinton campaign's communications director.

"Can the actual election come fast enough?" Palmieri said in summing up her feelings about the campaign’s final two weeks.

Nov. 3: A sigh of relief, or were the polls wrong?

RealClearPolitics national polling average: Clinton +1.3 percent/FiveThirtyEight forecast: Clinton 66.2 percent to win

The same day Clinton traveled to Arizona and Trump was urging himself to "stay on point," nail-biting Democrats got some good news from public polls in key battlegrounds taken during and after Comey’s seismic announcement.

A trio of polls had Clinton up 4-5 points in Pennsylvania. She also was narrowly ahead in Florida and North Carolina, although those surveys were well within the margin of error. The gold-standard poll in Wisconsin showed Clinton leading Trump by 6 points in the state.

As NBC’s First Read concluded on Nov. 3, "Team Clinton breathes sigh of relief, but they're not in the clear yet."

Clinton would go on to lose all four of those states on Election Day.

The national polls, it turned out, were fairly accurate: The final RealClearPolitics average had Clinton ahead by three points. And she ended up winning the national popular vote by 2 points, 48 percent to 46 percent, or nearly 3 million votes.

But the state polls were a different story, and it wasn’t just the public data. Clinton’s internal polling had her up by about 6 points in Wisconsin at the end of the election. Internal Trump numbers also showed Clinton ahead in the state, although by a smaller margin.

And the Republican National Committee was sharing numbers with reporters that had Clinton leading in Florida.

"Everyone’s data was wrong — in the same direction — and that created a conventional wisdom that was off," said Nayak of the Clinton campaign.

Nov. 4: "Boy, I love reading WikiLeaks"

RealClearPolitics national polling average: Clinton +1.6 pecent/FiveThirtyEight forecast: Clinton 64.5 percent chance to win

Another major plot in the presidential race was Russia’s alleged intervention in the contest — a story that continues to unfold today.

Less attention, however, has been paid to how Trump and his team seized on that Russian meddling, which the U.S. intelligence community says included the hacking of Clinton campaign chair John Podesta’s emails — and their release via WikiLeaks.

The revelations from Podesta's emails — including excerpts of Clinton’s paid speech to Goldman Sachs, advisers’ candid criticisms of their candidate and a memo on "Bill Clinton Inc." — all fueled negative headlines. And Trump pounced:

Oct. 31 in Warren, Mich.: "Did you see where, on WikiLeaks, it was announced that they were paying protesters to be violent, $1,500?... Did you see another one, another one came in today? This WikiLeaks is like a treasure trove"

Nov. 2 in Orlando, Fla.: "WikiLeaks just came out with a new one, just a little a while ago, it's just been shown that a rigged system with more collusion, possibly illegal, between the Department of Justice, the Clinton campaign and the State Department"

Nov. 4 in Wilmington, Ohio: "Boy, I love reading those WikiLeaks"

NBC News counted 145 mentions of WikiLeaks by Trump in the last month of the race.

Beyond the headlines and attacks from the stump that they produced, the WikiLeaks revelations hurt Clinton because voters couldn’t tell the difference between them and the longstanding controversy surrounding Clinton’s own emails, according to top campaign officials.

"People conflated WikiLeaks with Hillary’s emails," said Palmieri, Clinton’s communications director.

"Benghazi, Comey, WikiLeaks all sounded like the same thing to voters," added Robby Mook, the campaign manager.

(Both Russia and WikiLeaks have denied that Russia was behind the 2016 hacks and email revelations.)

Nov. 6: "It's a totally rigged system"

RealClearPolitics national polling average: Clinton +1.8 percent/FiveThirtyEight forecast: Clinton 64.9 percent chance to win

Comey wasn’t finished making news in the final two weeks of the election. And once again, it was Chaffetz who broke it first.

"FBI Dir just informed us 'Based on our review, we have not changed our conclusions that we expressed in July with respect to Sec Clinton,'" Chaffetz tweeted about the second letter Comey had sent to Congress.

Part of a Nov. 6, 2016, letter from FBI director James Comey to Congress. Jon Elswick / AP

In other words, the FBI’s investigation into those additional emails didn’t uncover anything new. Nearly all of them were duplicates of emails the agency had already seen.

Trump railed against Comey's second letter, and he used it to re-litigate the controversy over Clinton's emails, telling voters it was now up to them "to deliver justice" on Election Day since no one else would.

"Right now, she is being protected by a rigged system. It's a totally rigged system," Trump said in Michigan.

"Hillary Clinton is guilty. She knows it. The FBI knows it. The people know it. And now it's up to the American people to deliver justice at the ballot box on Nov. 8th," Trump added.

For the Clinton campaign, Comey’s second letter appeared to be great news — it looked like Clinton was in the clear of any wrongdoing.

But months later, top officials believe the second letter only revived the email story two days before the election.

"At best, it hurt as much as it helped," said the Clinton campaign’s Shur. "It just brought it all up again," Palmieri added.

On May 3, Sen. Dianne Feinstein, D-Calif., asked Comey at a Senate hearing why he made that Oct. 28 announcement in the first place, especially given existing Justice Department guidelines against interfering in upcoming elections.

Comey replied that he faced two options: One, speak about the newly found emails. Or two, conceal them.

"Speak would be really bad. There's an election in 11 days. Lordy, that would be really bad," he told Feinstein. "Concealing in my view would be catastrophic, not just to the FBI, but well beyond. And honestly, as between really bad and catastrophic, I said to my team we've gotto walk into the world of really bad. I've got to tell Congress that we're restarting this."

He added, "It makes me mildly nauseous to think that we might have had some impact on the election. But honestly, it wouldn't change the decision."

Comey was fired six days after that testimony.

Nov. 8: Election Day

RealClearPolitics national polling average: Clinton +3.2 percent/FiveThirtyEight forecast: Clinton 71.4 percent chance to win

Despite the jarring events of the final two weeks, all signs still pointed to a Clinton victory. The early-vote numbers from Florida and Nevada looked good for the campaign. And the last national polls — from NBC News/Wall Street Journal, ABC/Washington Post, CBS and Bloomberg — boosted Clinton’s lead in the RealClear average above three points.

But Trump clobbered Clinton in the voting on November 8, especially in key battleground states, as contrasted with the early voting.

Take Florida, for example: Nearly 70 percent of votes were cast in the state before Election Day, and Clinton enjoyed an estimated 4-point lead over Trump — about 240,000 votes.

Voters line up to vote early at the Supervisor of Elections office on October 24, 2016 in Bradenton, Florida. Joe Raedle / Getty Images

"[Trump] won Election Day by 13 points," said Democratic strategist Steve Schale, who closely examined Florida’s early-vote numbers.

According to the exit poll data, Trump won those who said they decided their vote in the last week by 11 points in Michigan, 17 points in Pennsylvania and Florida, and a whopping 29 points in Wisconsin. (By contrast, Clinton won the late deciders in Virginia — a state she carried by five points.)

From the Trump team’s perspective, the final 12 days of the campaign allowed them to pull off perhaps the greatest political upset in American history.

The Trump analytics data that showed him with only a 15 percent chance of winning on Oct. 27 was up to a 35 percent chance by Election Day — and that was assuming Trump wasn’t going to win Florida.

"We still didn’t think he was going to be the definitive winner," said Oczkowski. "But 35 percent is within striking distance."

But for the Clinton campaign, the final 12 days — Comey, WikiLeaks, a more disciplined Trump and drubbing in key battlegrounds on Election Day — represented their worst two-week stretch of the general election.

"Campaigns have been told for years to expect the unexpected. But in this election we needed to expect the unbelievable, and we didn't," said Jesse Ferguson, the Clinton campaign’s deputy national press secretary and senior spokesperson.

"A lot of things came together to create what happened," Mook, Clinton’s campaign manager, told NBC News. "We had a bunch of black swans that converged on us."