Early this morning, after he had stunned the world by winning the presidency, Donald Trump took a call from a longtime confidant.

"Nobody believed in me," Trump said. Literally, only two or three people, he said, had thought he could pull this off -- and at times, not even Trump himself. Now he had a lengthening call list of world leaders who wanted to pay their respects to the new leader of the free world.

It was a starkly different scene last June, when the businessman was still seen as a hopeless underdog. Trump was on his blue-and-red Boeing 757, huddling with his top staffers, who were begging him not to talk about Gonzalo Curiel.

Trump had a score to settle. He told his staff he wanted to denounce the judge handling the lawsuit against Trump University. His advisers pushed back hard, saying this would be a huge distraction, that Trump had to be seen as fighting for America, not for himself.

The unofficial Republican nominee took the plunge anyway, calling the Indiana-born judge, whose parents were from Mexico, a “hater” who had “an inherent conflict of interest.”

Those attacks, denounced by some Republican leaders, created a political uproar that haunted the campaign for weeks. It was an early harbinger of a self-destructive tendency that would damage Trump’s candidacy again and again: his insistence on straying from scripted messages to indulge in attacks and counterattacks against those he felt had wronged him.

It was that compulsion to repeatedly blow past the stop signs erected by his strategists that one confidante described as a condition: “defiance disorder.”

The back story of this campaign is how some of Trump's advisers tried again and again to rein him in, failing time after time, and privately concluded that he could not be managed -- and therefore was unlikely to win. Only in the final weeks, when the race seemed all but lost, did Trump find a way to stop stepping on his message -- and paved the way for his stunning upset.

Trump was a genuine phenomenon, an outsider who used gut instincts, media mastery and a blunt, often divisive message to beat better-funded rivals and outfox an often hostile press corps.

But throughout the long campaign, Trump's greatest strength was his most glaring weakness, one that frustrated a rotating cadre of advisers until the very end. His tough street talk was both popular and polarizing; his stream-of-consciousness delivery both mesmerizing and undisciplined; his Twitter attacks both devastating and distracting. At times, even his fiercest loyalists wondered whether he really wanted the presidency, which once seemed far out of reach but came to be a tantalizing mirage, receding as he came closer.

Internal rivalries on the tiny team didn’t help matters. Corey Lewandowski, his first campaign manager, harnessed Trump’s energy but drew flak for giving the candidate too much leeway (though he pushed back when necessary). The second, Paul Manafort, took heat for spending time in the Hamptons and lacking a personal rapport with Trump (though his mission was to mend fences with the Beltway establishment). The third, Kellyanne Conway, was chided for spending too much time on TV (a chief part of her job) and contradicting some of Trump’s statements (though she remained grounded in facts, such as the poor poll numbers he tried to dismiss as phony).

Most campaign aides viewed Jared Kushner, Trump’s son-in-law, the 35-year-old publisher of a Manhattan weekly with no political experience, as the de facto campaign manager. There was a growing sense at the top that no one wanted to cross Ivanka’s husband or bring bad news to the candidate. Ivanka, Eric and Don Jr. would weigh in to counter what they saw as bad advice, but they and others would also send uncomfortable messages through Hope Hicks, Trump’s low-key press secretary. Hicks, 28, was constantly at his side, a former fashion model who became such a trusted counselor that Trump would openly worry, when he flouted the team’s directives, about disappointing her.

“Can I win? Can I win?” Trump would ask his strategists in the closing weeks, though he often defied their advice, refusing to eliminate trips to Pennsylvania, Colorado and other states that he had virtually no chance of winning.

Over and over, the real estate mogul displayed a fingertip feel for public sentiment and remarkable ability to bounce back, despite being written off by what he came to view as the corrupt media. He would criticize Mexican rapists, John McCain, Carly Fiorina’s face, call for a temporary ban on Muslim immigrants, and yet drive the news agenda and keep on winning. But that was with Republican primary voters.

On the broader stage, running against a Democrat whose unpopularity nearly matched his, Trump’s own words became the most potent weapons against him.

The pattern was remarkably consistent. Trump would hone a successful message, stick to the script — often reading from once-disparaged teleprompters — and wind up chafing at the rhetorical shackles.

His savvier advisers would realize that he wasn’t having fun. And then he would rebel. He would create a new narrative. It could be a phrase, a tweet, an extended riff in front of a rapturous crowd. Trump would mar the story line, blame the media for twisting his words, keep defending or tweaking his remarks, and suddenly he was no longer talking about taxes or terrorism.

**

Over the summer, Trump retweeted an anti-Hillary graphic with a pile of cash and what looked like a Star of David. When the ensuing flap prompted his staff to delete the star, Trump was furious. He denied the image was anti-Semitic, attacked Clinton, kept talking about it and turned what might have been a half-day incident into a running story.

When a gunman killed 49 people at a gay nightclub in Orlando, Trump didn’t issue the usual thoughts-and-prayers refrain. Instead, he tweeted: “Appreciate the congrats for being right on radical Islamic terrorism, I don't want congrats, I want toughness & vigilance.”

He dug a deeper hole the next day on “Fox & Friends,” faulting President Obama for his approach to radical Islamic terrorism: “We're led by a man that either is not tough, not smart, or he's got something else in mind.” His strategists were stunned as critics assailed Trump for insinuating that an American president might be sympathetic to terrorism.

But Trump refused to budge, again dragging out the controversy. “I don’t think Orlando was a mistake at all,” he told me. “I’m saying what everyone else is saying and thinking. The problem is everyone wants to be politically correct, and you can’t be politically correct because these people are after our country.”

During the Democratic convention, Trump held a news conference -- his favorite venue for stealing attention -- and said this about his rival: “Russia, if you’re listening, I hope you’re able to find the 30,000 emails that are missing.” Though it seemed like a tongue-in-cheek comment, the press went haywire, the New York Times sternly accusing him of “essentially urging a foreign adversary to conduct cyberespionage against a former secretary of state.”

That was a ripple compared to the tidal wave of negativity unleashed after Khizr Khan and his wife, who had lost a son in Iraq, castigated Trump at the Philadelphia convention. Trump told ABC’s George Stephanopoulos that “if you look at his wife, she was standing there, she had nothing to say, she probably — maybe she wasn’t allowed to have anything to say.”

The staff pounced on him. One adviser told Trump that he was getting “killed” over the issue, that he had dropped 5 to 7 points in the polls, that he could not sustain this. Trump knew it was a losing issue, his strategists believed, but could not let go.

Trump kept up his assault on the Gold Star family for days as his strategists frantically tried to change the subject. Once again, Trump’s insistence on punching back at his detractors -- no matter how ill-advised -- badly hurt him.

But even then, Trump believed he had said nothing wrong. “The media was not treating the statements fairly,” he told me. “I mean, they would chop them up and then shorten the statement, and it didn’t sound proper or didn’t sound as good when they did that. It was very unfair.”

**

All these factors -- Trump’s unorthodox style, pugilistic instincts and a staff torn between professionals and family members -- came together in the runup to the first debate at Hofstra University. Too many people were involved in debate prep, drifting in and out, including two generals with no political experience. Trump got too much conflicting advice. Advisers would send memos, but the candidate had little patience for anything longer than a paragraph and preferred verbal briefings. Supremely self-confident, he refused to follow the conventional practice of holding mock debates.

Trump stumbled against Clinton but insisted he had won the debate, calling surrogates to complain that they weren’t sufficiently defending him on the air. Some advisers felt he was too smart not to know the truth but too proud to admit it.

Worse, he had taken the bait on one of Clinton’s last answers, when she accused him of mocking the winner of his Miss Universe pageant two decades ago by calling her Miss Piggy.

On “Fox & Friends” the next morning, Trump raised Alicia Machado without even being asked, saying: “She was the worst we ever had -- the worst, the absolute worst. She was impossible…She gained a massive amount of weight and it was a real problem.”

For nearly a week, the candidate who trailed badly among women was insisting that a onetime beauty queen no one had heard of was a terrible person and too fat. He even tweeted that people should check out her “sex tape” (actually an under-the-covers scene in a Latino reality show). His staff was unable to persuade him to move on.

Trump sympathizers wondered why his staff didn’t boot him from Twitter. But Conway believed she couldn’t take his phone away, that he was a 70-year-old man who would ultimately say and do what he wanted. She managed him as best she could, sweet-talking rather than lecturing him, and when asked about Trump comments she couldn’t defend, she simply deflected the questions.

While prepping the candidate for the final debate in Las Vegas, Trump’s team drove home one answer, literally dozens of times. With Trump having spent days talking about a “rigged” election, the inner circle drilled him to say that while the media were unfair, of course he would accept the outcome on Election Day. He was explicitly warned that any other answer would guarantee 48 hours of bad press, wiping out the rest of the debate.

But when Chris Wallace asked that very question, Trump went rogue. He said he didn’t know what he would do and would keep the country in suspense. As Steve Bannon, Conway and their team watched, their faces fell. They could not believe it. A modified statement was issued the following day, but Trump, before the last mass audience of the campaign, was defiant. He went with his gut. Those who knew him best knew the truth: He would not be managed.

Trump attempted a reset by giving what was touted as a major policy speech in Gettysburg, where he would unveil a detailed Contract with the American Voter.

But Trump spent several minutes ripping the nine women who had accused him of sexual misconduct, calling them liars and vowing to sue them after the election.

The press, naturally, took the bait. A presidential candidate threatening litigation against women who accused him of unwanted groping and kissing was a hotter story than a laundry list of proposals, as Trump, after decades of dealing with the New York tabloids, undoubtedly knew.

Trump had again stepped on his own story, much to the chagrin of his advisers. Some believed he was so frustrated by the allegations, and having to deny them to his wife Melania, that he couldn’t resist fighting back in his signature style.

**

On Friday, Oct. 28, Trump was in a lousy mood. He was supposed to fly to New Hampshire for a campaign event, but he was two hours late in leaving Trump Tower. Instead, trailing in the polls, he spent 45 minutes complaining about how he had been trashed on MSNBC’s “Morning Joe,” a show he frequented during the primaries but now regularly attacked.

By the time he landed in New Hampshire, the stunning story about James Comey launching a new FBI probe of Clinton’s emails had broken. Trump huddled with Bannon, the campaign chairman, policy aide Steve Miller and Lewandowski, now an informal adviser. Bannon, whose low-key demeanor tended to keep Trump calm, urged restraint.

While retired Gen. Michael Flynn had to keep warming up the crowd beyond his usual one-minute spiel, Bannon helped add a few sentences to Trump’s speech on the teleprompter.

“Perhaps finally justice will be served … Clinton’s corruption is on a scale we have never seen before,’’ Trump told the Manchester crowd.

The aides promptly canceled scheduled interviews with two New Hampshire stations and a taping for “Meet the Press.” Trump’s inclination was to do a TV blitz, but most of the advisers wanted him to go dark, and for several days he did. Every day he wasn’t on television, they believed, he was winning — especially while Clinton had become the story.

If Trump was doing interviews, they argued, he would be asked about every damaging story in the papers. Isn’t it true, an anchor would ask, that you avoided hundreds of millions of dollars in income taxes by using a dubious loophole? Isn’t it true that you claimed credit for major charitable donations that you didn’t make? And Trump would inevitably toss out the talking points and aggressively defend himself, drawing attention from the FBI probe that had cast a pall over Clinton’s campaign.

Instead, an energized Trump, buoyed by the tightening polls, stuck to the prepared speeches, surrendering the TV weapon that had powered his rise to the nomination and beyond. “Stay on point, Donald,” his advisers would insist, and this time Trump complied, except for one swipe at NBC’s Katy Tur during a rally, which drew negative attention.

His strategists kept some of their internal polls from him -- such as one showing him trailing by low double digits in New York -- because they knew he would want to campaign there rather than in swing states he might actually win. After a year and a half, they finally had the candidate on track and on message.

Trump’s team was a bit deflated when Comey cleared Clinton on the new batch of emails less than 48 hours before Election Day, figuring that lifted a cloud -- and was worth a point to Hillary in such do-or-die states as Michigan, Pennsylvania and New Hampshire. The important thing was that Trump was fired up, he saw a path to 270, months after many pundits predicted he would be the biggest loser since Barry Goldwater. And for Trump, as he raced to the final flurry of rallies, mindset was everything.

He couldn't resist calling into Fox twice on Election Day, breaking his media silence and drawing the question that had dogged him for weeks: What if he lost? "I have to see, and under what circumstances," the candidate told Martha MacCallum, again invoking a "rigged system" less than four hours before the first polls closed.

In the end, that question was moot. Trump and his team knew from their internal reports, perhaps two hours before the AP and the networks called the race, that he had accomplished what everyone said was impossible.

Trump's defiance enabled him to pull off a "miracle," which is what Politico had said on Tuesday morning that he would need. The man who broke every rule in the political handbook had captured the White House.