Donald J. Trump’s campaign couldn’t have scripted the results in Iowa any better.

Except for a single vote.

Standing backstage at his victory party in downtown Des Moines, Mr. Trump appeared almost giddy with disbelief as television screens blared the news of an outcome so lopsided it was called while the voting was still underway. He had won more than 50 percent of the vote — and 98 of the state’s 99 counties — and his rivals, Ron DeSantis and Nikki Haley, were clustered together far behind. Mr. DeSantis edged just ahead of Ms. Haley, enough to stall her momentum but not enough to save his candidacy.

“Did you think it was going to be like this?” Mr. Trump remarked to an adviser, according to two people who witnessed the interaction.

That night, the former president and his usual coterie of top aides were joined by about a dozen Iowa staffers headed for New York, boarding the plane his campaign calls Trump Force One.

Not everyone was invited. Mr. Trump had lost Johnson County, home of the University of Iowa, by a single vote. The regional political director who had overseen the area was not given a seat on the plane. The next morning, according to two people familiar with the matter, she was informed by a terse email from her supervisor that her contract with the Trump campaign was not being renewed.

It was the type of ruthlessness the Trump team had deployed in the prior 14 months: Win — or else. The approach has fit the requirements of a candidate who faces the threat of imprisonment if impending trials and the 2024 presidential race do not go his way.

On Tuesday, Mr. Trump beat Ms. Haley by 11 percentage points in New Hampshire, the early state where she had not long ago seemed best situated to score an upset win. His victory came only one week after Mr. DeSantis lost Iowa, his strongest early state, so badly he exited the race.

How Mr. Trump swept the first two states — smoothing his path to the nomination at this early stage — is certainly a tale of cutthroat politics. But that’s only part of the story.

The former president and his allies had luck and a cunning strategy on their side. They put Mr. Trump’s unerring instincts for revving up the Republican base and belittling his opponents to effective use. He benefited from criminal indictments that rallied Republicans around him and a fractured opposition that spent millions of dollars savaging each other instead of him — a replay of the 2016 Republican primaries. Along the way, Mr. Trump consistently evaded ideological labels, along with misguided and mistimed efforts to diminish him.

In 2016, Mr. Trump finished in fifth place among voters in Iowa who had said “shares my values” was their top criteria, winning a meager 5 percent of such voters, according to entrance polls. In 2024, Mr. Trump dominated that category, pulling in 43 percent of those voters.

Mr. Trump’s values had not changed. The party’s had.

The Trump team couldn’t believe its luck in October when Ms. Haley’s super PAC began to reserve advertising time attacking Mr. DeSantis.

From the beginning of the campaign, Mr. Trump and his top advisers had seen Mr. DeSantis as their only serious rival. They had spent months savaging him. Ms. Haley had started her campaign with no money and with polling in the single digits. But by fall she was vying with Mr. DeSantis in early-state polls after her August debate performance won positive reviews.

The anti-DeSantis spending from Ms. Haley’s largest super PAC, SFA Fund, kept rising: $1.3 million in October expenditures, $4.4 million in November. It ballooned in December to $15.2 million — with almost all the money going to crush Mr. DeSantis in his must-win state of Iowa.

“Nikki Haley spent millions of dollars on TV attacking Ron DeSantis so we didn’t have to,” said Chris LaCivita, a top campaign adviser to Mr. Trump.

One especially cutting ad from the Haley super PAC repurposed parts of a 2018 commercial from Mr. DeSantis’s primary campaign for governor that featured Mr. DeSantis teaching his children by using Trump slogans and reading from Mr. Trump’s book “The Art of the Deal.” The super PAC’s new anti-DeSantis ad interspersed those 2018 clips with a crowd chanting “Who’s your daddy?”

The ad was a sharp dig at Mr. DeSantis, but not only because of its content: The “Who’s your daddy” ad was produced by Something Else, the same firm that made the original DeSantis ad in 2018. In his career, Mr. DeSantis’s management style has left a long wake of antagonized former aides, including some now at the top ranks of the Trump campaign.

Ms. Haley’s rise also drained Mr. DeSantis’s resources. One of his allied super PACs, Fight Right, spent 25 times as much money, nearly $10 million, attacking Ms. Haley compared with what it spent hitting Mr. Trump, federal records show.

And the money kept coming. On Nov. 28, one of the most financially powerful institutions on the right came to Ms. Haley’s aid. The political network founded by the billionaire industrialist brothers Charles and David Koch endorsed Ms. Haley and began spending millions of dollars to elevate her. It deployed its massive field organization to knock on doors in Iowa and New Hampshire — giving her a ground army she could not have afforded on her own.

But several Koch network donors began raising questions about the decision.

The investor Chart Westcott sent a text message to other Koch donors, describing the endorsement as a “half-baked moonshot,” adding that “outside of Trump being a corpse, there is no path, zero, for Haley to the nomination.”

The circular Republican firing squad — with the bullets aimed at everyone besides the guy who led the race — represented a replay of the 2016 primary campaign. In that race, Mr. Trump’s well-funded rivals spent tens of millions of dollars destroying one another and left Mr. Trump largely unscathed.

“For a second primary cycle, no one laid a glove on Trump with paid media,” Chris Christie, the former governor of New Jersey who dropped out of the presidential race earlier this month, said in a brief interview. Mr. Christie had consistently lashed Mr. Trump on the stump and aired critical ads, but he did not have the resources to fund a significant effort on television.

The one well-funded organization that did try to attack Mr. Trump early through paid media — an offshoot of the Club for Growth, a conservative anti-tax group — quickly concluded that its effort was futile. The group’s leader, David McIntosh, wrote a memo in September that effectively waved the white flag. Nothing had dented Mr. Trump, and tests showed that some ads had even backfired and strengthened Mr. Trump.

A spokeswoman for Ms. Haley, Olivia Perez-Cubas, said in response in an interview that Ms. Haley had begun at 2 percent in a 14-person race and that “in a few months, we cleared the field, raced to 43 percent in New Hampshire and made it a two-person race. We’re just getting started.” She added that Ms. Haley would continue to fight for “the 70 percent of all Americans who don’t want a Biden-Trump rematch.”

Trump advisers were stunned that no lessons had apparently been learned from 2016. Even the two early-state Republican governors determined to defeat Mr. Trump in 2024 found themselves working at cross purposes. Gov. Kim Reynolds of Iowa endorsed Mr. DeSantis. Gov. Chris Sununu of New Hampshire backed Ms. Haley.

Once again, Mr. Trump’s opponents had divided and conquered themselves.

By late December, something unexpected had happened.

Mr. DeSantis had been so thoroughly hobbled by the combined Trump and Haley forces that the Trump team no longer saw him as a serious threat. He was still somewhat a force in Iowa. But he had plunged to single-digit support in New Hampshire and South Carolina.

A brutal Trump effort to mock Mr. DeSantis, which began months before his entry into the race, had proved politically lethal. The Trump campaign’s gutter-level efforts to smear him — questioning his sexuality, mocking his heeled boots — were supplemented by a paid campaign on policy that ran national ads about his interest in changing Social Security.

“We decided early on that we would take the unorthodox step of defining DeSantis early — well before he entered the race — to undermine his electability argument and soften his numbers with Republicans,” said Tony Fabrizio, the pollster and strategist for MAGA Inc., a pro-Trump super PAC. “What we didn’t expect was that the DeSantis team’s hubris would allow our attacks to go unanswered.”

One moment of vulnerability for Mr. Trump stood out as a missed opportunity for Mr. DeSantis.

When the former president said in September on NBC’s “Meet the Press” that Mr. DeSantis signing a six-week abortion ban was a “terrible mistake,” internal metrics showed his support among the most conservative voters dipping. To the Trump team’s surprise, the DeSantis operation did not quickly seize on the remark and amplify it in paid media. Soon Mr. Trump had recovered, with a blitz of direct mail targeting social-conservative voters in Iowa.

By the fall, the DeSantis operation was mired in a mess of dysfunction. The campaign had run short of money over the summer, so the main super PAC supporting him, Never Back Down, shouldered a growing burden. But as the super PAC tore itself apart with infighting, resignations and firings, DeSantis allies formed a new group, Fight Right, to run anti-Haley commercials.

The focus of Fight Right’s anti-Haley ads seemed to mirror exactly what the DeSantis campaign wanted. But internal data from Never Back Down, described by a person familiar with it, showed that the ads that Fight Right was airing were using topics, including Ms. Haley’s stance on transgender issues and the suggestion that she was inspired by Hillary Clinton, that might have actually been helping her among some of the persuadable voters left in the Republican primary.

Ken Cuccinelli, a Never Back Down board member, objected at one point to Fight Right’s anti-Haley ads, saying in an internal message that the ads from the DeSantis group should be treated like an in-kind contribution to Ms. Haley, according to the person who described the correspondence. Mr. Cuccinelli resigned from the group’s board in December, though his departure has not previously been reported, and he stayed on as an adviser.

As Iowa neared, it was Ms. Haley’s surge that was the cause for concern for the Trump team. His advisers never worried that she might defeat the former president in the state. But they knew that if Ms. Haley finished a strong second ahead of Mr. DeSantis, there was a risk that she could shoot out of Iowa with enough momentum to eclipse Mr. Trump in New Hampshire.

The final result in Iowa, with Mr. DeSantis barely edging Ms. Haley, was optimal for Mr. Trump. Mr. DeSantis had nowhere to go and Ms. Haley had been slowed.

In Iowa, Mr. Trump happily watched the results roll in, taking pictures with staff members in front of television screens showing the landslide, inviting advisers onstage with him and declaring, according to two people who were there, that he wanted to deliver his remarks without a teleprompter, dictating some notes and scribbling in markers. Onstage, a beaming Mr. Trump made what, for him, amounted to magnanimous remarks about his vanquished opponents.

It was a far cry from his tone a week later in New Hampshire.

By the time Mr. Trump flew out of Iowa, the plan to squash Ms. Haley, his former United Nations ambassador, in New Hampshire was well underway.

The Trump campaign and its allied super PAC spent millions of dollars hammering her with television ads, squeezing her simultaneously from the left on Social Security — just as his operation had done with Mr. DeSantis — and from the right on immigration.

Ms. Haley had attacked Mr. DeSantis in Iowa, but until the final stretch before the New Hampshire primary she had handled her former boss more gently, emphasizing that she had voted for him and agreed with many of his policies. The “chaos” she complained of was often hedged by the idea that it followed him “rightly or wrongly.” This continued even as he mocked her birth name and floated a preposterous conspiracy theory that she was ineligible to be president because her parents were Indian immigrants.

In private discussions, Mr. Trump had dangled the possibility of a Haley vice presidency for weeks. He only said publicly that she was not cut from the proper “timber” days before New Hampshire voted — and after Ms. Haley had said being his running mate was “off the table.” It was after the “timber” remark that Ms. Haley more explicitly questioned Mr. Trump’s mental acuity.

But unlike the Trump team, which repeated over and over only a few messages against Ms. Haley, burning them into voters’ minds, television records show the Haley team and her super PAC cycled through five different ads in the closing days before the New Hampshire primary.

The Trump team replicated against Ms. Haley a strategy it had used to powerful effect last spring against Mr. DeSantis: deploying home-state endorsements against her, with devastating sequencing and public displays.

In the last days before the primary, Mr. Trump, online and onstage, boasted of endorsements from senior elected officials from South Carolina — the state where Ms. Haley served as governor. It was designed to send a message to voters: What did it say about Ms. Haley if the top officials from her home state, some of whom she had personal histories with, wanted somebody else?

In response, Ms. Perez-Cubas, the Haley spokeswoman, said: “Nikki has always been the outsider candidate fighting the Washington elites. It’s Trump who has become the establishment.”

As the polls opened in New Hampshire, the Trump team wavered between confidence and anxiety. They knew he had a strong grip on Republicans but the big unknown was how many independent voters would show up for Ms. Haley.

The answer was a lot. But Mr. Trump’s hold on the Republican base was overwhelming: Exit polls showed him winning 74 percent of registered Republicans — a margin so large it swamped Ms. Haley’s strength with independents, and showed how steep her path would be going forward.

Still, Mr. Trump grew agitated as he watched returns with aides in a room at the Sheraton hotel in Nashua, N.H. He was gobsmacked when Ms. Haley took to the stage and gave what he heard as an attempt to frame her loss as a victory.

“Why didn’t I go first?” Mr. Trump asked his aides.

Ms. Haley’s speech seemed designed to get under Mr. Trump’s skin. She questioned his cognitive abilities — a sore point for him for years.

By the time he took the stage in the Sheraton ballroom, Ms. Haley had lodged herself firmly inside his head. He fired one shot after another, even mocking her outfit. It didn’t sound like a victory speech. Ms. Haley later called it a “temper tantrum.”

He had won the first two states — a feat never achieved by any Republican who wasn’t a sitting president. But Mr. Trump had grudges to settle, mocking his former press secretary Kayleigh McEnany in a social media post aboard his plane. “I don’t get too angry,” he had explained during his speech. “I get even.”