U.N. Ambassador Nikki Haley, who abruptly announced her departure Tuesday, will leave behind a job she helped elevate to one of the most influential in the Trump administration, raising the stakes for her successor and fueling speculation about her future.

Haley served almost as a shadow secretary of state during the first year of the administration, wielding more influence than the man who held the job, Rex Tillerson, and winning the confidence of President Trump with her strong defense of his policies at an institution filled with foreign officials opposed to his worldview, even as he sometimes chafed at her ambition.

Her influence has been curtailed in recent months as new national security adviser John Bolton and Secretary of State Mike Pompeo reclaimed policy and political ground that their predecessors ceded, but she departs with her relationship with Trump intact.

“She’s done a fantastic job, and we’ve done a fantastic job together,” Trump said during a cordial Oval Office meeting with Haley before reporters. “She’s a fantastic person, very importantly, but she also is somebody that gets it.”

Haley portrayed her departure as coming at a natural time — after accomplishing what she wanted. Many senior officials were surprised by the announcement and learned she was leaving just minutes before the news leaked — she was already in the West Wing with Trump preparing for the announcement — and lamented that it came so quickly after the confirmation of Justice Brett M. Kavanaugh to the Supreme Court, which the White House hoped would continue to receive heavy news coverage.

“It was a blessing to go into the U.N. with body armor every day and defend America,” Haley said. “And I’ll always do that; I’ll never truly step aside from fighting for our country. But I will tell you that I think it’s time.”

Outgoing U.N. ambassador Nikki Haley on Oct. 9 said the country's international standing improved in the last two years, and that "the U.S. is strong again." (The Washington Post)

With questions swirling about what she will do next, Haley was quick to shoot down the idea that her ambitions include taking on Trump if the president looks vulnerable heading into his reelection in 2020.

“For all of you that are going to ask about 2020 — no, I’m not running for 2020,” Haley said unprompted with Trump sitting beside her. “I can promise you what I’ll be doing is campaigning for this one. So, I look forward to supporting the president in the next election.”

Trump grinned through her remarks — but they startled White House aides who already viewed her warily as a potential threat and a skeptic of the president’s overall agenda.

“That’s so good, Nikki,” Trump said. “Thank you.”

Haley’s ability to raise the profile of the job of U.N. ambassador has focused more attention on who will replace her than is usually the case.

Speculation swirled throughout the day that Trump’s daughter Ivanka could be a contender, a move that would allow her and her family to return to New York.

The president seemed eager to play along with the idea, telling reporters she would be “dynamite” before conceding she would face nepotism concerns.

Ivanka Trump killed the rumor later in the day tweeting that her father would find a “formidable replacement” for Haley but that it “will not be me.”

That left the speculation focused on former senior White House aide Dina Powell, who Trump said is under consideration. Some Trump advisers were pushing Richard Grenell, the ambassador to Germany, for the post. 

Trump told reporters while on Air Force One heading to a rally in Iowa on Tuesday night that he has five names on his short­list and that Grenell is not one of them.

“He is doing so well in a position that is so important,” Trump said. “Ric is doing so well that I wouldn’t want to move him. I’d personally rather keep Ric where he is.”

Haley’s resignation will be effective in January, which she wrote in her resignation letter would give Trump time to choose and confirm a replacement.

Haley, 46, has long been mentioned as a potential Republican presidential or vice presidential candidate. Speculation had focused on 2024, after Trump either lost reelection or served a second term, but shifted to 2020 as Trump’s potential legal problems mounted.

Advisers said Haley was not interested in a Senate seat and was more likely to take board seats or secure other lucrative positions until after the 2020 election, noting her limited finances.

“She needs to make some money,” said one adviser who speaks to her regularly.

Another adviser said regarding the timing of her departure that Haley had little to gain politically by staying in the job.

“She knows there is nothing good that comes of staying around much longer,” one close adviser said. “She leaves with a good reputation, on her own terms, and with the president still good with her.”

Haley took pride in keeping distance from the daily drama of the White House and she was determined to depart on her terms, both White House and Haley advisers said.

While she maintained a good relationship with Trump throughout her tenure, the president was also leery of her ambitions and grew frustrated at times when she made announcements on TV — such as discussing new sanctions against Russia — or when he saw large amounts of glowing press about her. She also made communications and policy moves without warning the communications staff, White House aides said.

Haley has been privately skeptical of some of Trump’s politics and tactics but has also marveled at his crowds and poll numbers. She was careful even at off-the-record dinners not to be critical of Trump, diplomats and friends who ate with her said.

While not in his inner circle, officials said, Haley was able to speak honestly and directly with Trump.

Thomas Bossert, a former homeland security adviser, said that she was often more candid with the president than other aides — and that Trump appreciated it. “She was not nervous on what to think or feel, and she was entirely comfortable in her own skin,” he said. “Presidents get frustrated with that, and this one in particular can smell that. She was straightforward, tough and competent with him.”

Several officials questioned why Haley announced her decision before the midterm elections if she plans to stay through the end of the year, but one of her advisers said she would have delayed making her decision public if that was what Trump wanted.

One day before Haley’s surprise announcement, she was the subject of an ethics complaint filed by a government watchdog group.

Citizens for Responsibility and Ethics in Washington (CREW) called for an investigation into seven free flights that Haley and her husband accepted last year on private planes from three South Carolina business executives.

A spokesman for the State Department referred questions about the complaint to the inspector general’s office, which declined to respond to requests for comment.

Haley leaves with foreign policy credentials and a national and international standing she did not carry as a governor, and without the damage to her reputation or standing suffered by others who quit or were fired during the Trump presidency.

A Quinnipiac poll in April found that Haley had the highest approval ratings of five Trump Cabinet members tested and was the only Cabinet member to hold majority approval among Democrats, Republicans and independents.

Overall, 63 percent approved and 17 percent disapproved of her performance as U.N. ambassador.

The cordial scene with Trump on Tuesday was all the more remarkable for the fact that Haley had quit during a private meeting with Trump on Oct. 3, nearly a week earlier. Trump and Haley agreed to announce it together this week, a Haley adviser said, and to tell almost no one else beforehand. Tuesday morning, there was a meeting with Haley, Trump and other staffers at which wording for the public announcement was discussed. No alternate explanation for her departure was given, according to a person with knowledge of the meeting.

Trump said he chose to make the announcement in the Oval Office because it seemed appropriate “when you really think somebody’s done a terrific job.”

Trump said Haley first told him about six months ago that she would like to “take a little time off” at the end of this year.

Haley’s tenure was praised Tuesday by fellow U.N. ambassadors, Israeli Prime Minister Benjamin Netanyahu, Defense Secretary Jim Mattis, Secretary of State Mike Pompeo, Senate Majority Leader Mitch McConnell (R-Ky.) and others.

Sen. Robert Menendez (N.J.), the ranking Democrat on the Senate Foreign Relations Committee, urged the White House to name a successor immediately.

“I am deeply concerned about the leadership vacuum she leaves and the national security impact of her departure at this time of continued disarray for this Administration,” he said in a statement.

During her time at the United Nations, Haley told fellow ambassadors she would “take names” when countries disrespected or worked against the United States, and she was a fierce defender of Trump’s agenda to confront Iran and defend Israel at the world body. She did not disguise disagreements with Trump, however, including over refu­gee and immigration policies that she argued harmed U.S. influence with allies.

Although Haley advanced Trump’s policies, she occasionally made public statements at odds with the White House and the president she served. 

In December, she said that women who had accused Trump of sexual misconduct “should be heard.” When a White House adviser said Haley had been confused in prematurely announcing more sanctions against Russia, she said simply, “With all due respect, I don’t get confused.”

Philip Rucker, Carol Morello, Beth Reinhard, John Hudson and Scott Clement contributed to this report.