Still pitching herself as a political outsider, Ms. Haley now has a political résumé that includes a stint in the Trump administration. Then there’s Mr. Trump himself.Nikki Haley was polling in the low digits, fighting for oxygen among better-known and better-funded rivals in a contest clouded by scandal and involving the man whose job they all sought.This was 2009, and Ms. Haley was the underdog candidate for governor of South Carolina. At the state Republican Party’s convention that year, she was the last contender to speak. Before she took the podium, Katon Dawson, then the state party’s chairman, handed her a rust-coated nail from a jar collected from an old building in Orangeburg.“‘Honey, this is a tenpenny, rusty nail,’” Mr. Dawson recalled he told Ms. Haley. “‘You’re going to need to be meaner and tougher than that to get through this.’”In Mr. Dawson’s telling, Ms. Haley was unfazed, responding: “‘No problem, I’m going to be governor.’”More than a dozen years later, Ms. Haley — who did become governor, went on to serve as U.S. ambassador to the United Nations, and is now running for president — hopes to replicate the kind of surprise success that made her a conservative star. As in prior races, she’s on a tight budget, spending conservatively, and keeping up a grueling schedule of appearances. As in campaigns past, her allies view the debate stage as crucial to building name recognition and buzz, and her poll numbers have climbed since her breakout performance onstage in Milwaukee.But the 2024 contest, in which Ms. Haley still trails former President Donald J. Trump as well as Gov. Ron DeSantis of Florida in national surveys, presents different challenges in a vastly altered political landscape.Though she is still pitching herself as an outsider who can take on the establishment, Ms. Haley now has a lengthy political résumé that includes a stint in the Trump administration. And much of the grass-roots support that helped power her victories in South Carolina has rallied behind her former boss, Mr. Trump.“The craziest, toughest, wildest, most stressful day working or running on a statewide gubernatorial campaign — that is three times a day, every day on a presidential,” said Kevin Madden, a former Republican operative who worked on Mitt Romney’s 2012 and 2008 presidential campaigns.Ms. Haley with former President Donald J. Trump when he accepted her resignation as ambassador to the U.N. in 2018.Samuel Corum for The New York TimesMs. Haley first stunned her party in 2004 when she ran for the State Legislature in a conservative district in Lexington County. She unseated Larry Koon, the longest-serving member in the South Carolina House of Representatives at the time and a fellow Republican with deep familial roots in the state.The daughter of Indian immigrants, Ms. Haley, 51, was an accountant helping her mother expand her international clothing shop. She had no political experience, and top consultants spurned her. She lagged in fund-raising and spent most of the race polling in the single digits. Even so, she was the target of ugly, racist attacks.Ms. Haley took those in stride, her friends said. She countered with the aggressive campaign schedule and retail politics that have become her signature, knocking on doors and passing out doughnuts.“I was discounted because I was a girl,” she writes of that first campaign in her memoir, “Can’t Is Not an Option.” “I was discounted because I was Indian. I was discounted because I was young.”Without leaning into any of those identities, Ms. Haley beat Mr. Koon by more than 9 percentage points.In the state House, Ms. Haley initially had few friends but soon earned the respect of colleagues for her work ethic and focus on policy. On the debate floor, she could be searing and was known to pick fights on issues she believed in.“I vividly remember her being active on several floor debates, and she was already a leader — that’s unusual for freshmen,” said David Wilkins, then the state House speaker who later led Ms. Haley’s transition team when she became governor and is now one of her presidential campaign donors.She turned a legislative dispute with Republican leadership — she wanted to hold more roll call votes — into a major policy issue of transparency in her first campaign for governor.As a freshman legislator, Ms. Haley quickly earned the respect of colleagues for her work ethic and focus on policy.Erik Campos/The State, via Associated PressMr. Dawson said that none of the “good ol’ boys” in South Carolina politics — himself included, at first — believed she had a real shot in that race. Her primary opponents were political heavyweights: Henry McMaster, a former state attorney general who is now governor; Gresham Barrett, then a popular U.S. Congress member; and André Bauer, then the state’s lieutenant governor.The race was complicated by Gov. Mark Sanford, a Republican ally who had all but officially endorsed Ms. Haley before he was swept up in a scandal over an extramarital affair. She faced more racist attacks. A conservative political blogger claimed he had an affair with Ms. Haley, which she vehemently denied.But she stuck to her playbook. Allies recalled her campaigning across the state on a shoestring budget while saving the little money she had for television ads. She drew the endorsements of powerful Republican allies who helped her thread the needle between big Republican donors and grass-roots Tea Party supporters. Among those allies were Mr. Romney, the former Massachusetts governor who was looking ahead to a second presidential run, and Sarah Palin, the former governor of Alaska and 2008 Republican Party vice-presidential nominee.She also had the support of Mr. Sanford’s wife, Jenny Sanford McKay, a popular figure in the state. The women had been acquainted ever since Ms. Haley’s first state House bid, when Mr. Dawson suggested Ms. Sanford McKay call and give the candidate weathering derogatory and racist attacks a pep talk. Ms. Haley did not really need it, she recalled.“She knew what she was doing, she knew why she was running and she seemed very confident,” Ms. Sanford McKay, who is now a Haley campaign donor, said in an interview.Ms. Haley celebrating with her family after winning the primary election for the South Carolina governor race in 2010.Travis Dove for The New York TimesOn the debate stage in Milwaukee, Ms. Haley did not surprise those who had watched her tussle with opponents in the past. Both allies and detractors have observed her talent for seizing opportunities — and for navigating changes to her own positions amid shifting political terrain, such as when she eventually supported removing the Confederate flag from the grounds of the South Carolina Capitol.As governor, Ms. Haley had initially expressed little to no interest in discussing the removal of the flag. But she changed her mind in 2015, after a white supremacist killed nine Black parishioners at an African American church in Charleston, S.C., including the Rev. Clementa C. Pinckney, a state senator. Joel Lourie, a former Democratic state senator who considered Mr. Pinckney a friend, said he had been one of Ms. Haley’s harshest critics until she “rose to the occasion.”“She is as tactical, talented and ambitious of a politician you will ever meet,” he said of Ms. Haley.Still, what worked for Ms. Haley in the past may not be enough in 2024, as she positions herself as both a friend to Mr. Trump, and the candidate best able to move the party beyond him in order to beat President Biden.“I can understand why she might have supreme confidence in her ability to win right now,” said Adolphus Belk, a political analyst and political science professor at Winthrop University in Rock Hill, S.C., recalling her strong performances at campus forums during her first bid for governor and later as governor.But the same Tea Party wave Ms. Haley tapped as part of her rise — grass-roots energy with deep strains of racism and white racial grievance that Ms. Haley and other Republican presidential candidates have continued to downplay — created the space for Mr. Trump’s climb to the White House and has allowed him to retain his dominance in the party and presidential field, Mr. Belk said.One striking example of how Republican politics has changed: Support from Mr. Romney, now a U.S. senator from Utah and a fierce critic of Mr. Trump’s, would be unlikely to help endear Ms. Haley to the primary voters she needs to woo.“She has managed to be pretty effective at contradiction over the years,” said Chip Felkel, a longtime South Carolina G.O.P. strategist. “But this is a bigger stage.”Ms. Haley sparring with Vivek Ramaswamy during a breakout performance in the first Republican primary debate last month in Milwaukee.Kenny Holston/The New York TimesThis time around, a bright spot has been a robust network of donors, and Ms. Haley raised more than $1 million in less than 72 hours after the debate, according to her campaign. She has held more than 90 events in the early states of Iowa, New Hampshire and South Carolina, and Ms. Haley’s campaign says the plan now is to keep up the pace. A super PAC backing her candidacy has started to pour money into advertising, with more than $9 million planned in spending in Iowa and New Hampshire from July to October, according to an analysis by AdImpact, a media-tracking firm. She has qualified for the second G.O.P. debate, which is scheduled for Sept. 27.Still, with months to go before the first nominating contest, Mr. Trump’s grip on the race has only appeared to tighten. He remains the top choice for G.O.P. voters nationally and in South Carolina, where Ms. Haley has been neck and neck for third or fourth place with her home state rival, Senator Tim Scott.“I’ll just say — take a deep breath,” Mr. Wilkins, one of Ms. Haley’s donors, said when asked about her position in the race. “She’s coming.” More