Nikki Haley will be resigning from her position as President Trump's ambassador to the United Nations at the end of the year, the president confirmed to reporters in the Oval Office Tuesday morning.

"She's done a fantastic job and we've done a fantastic job together," Trump said, announcing that Haley informed him six months ago she wanted to leave after two years. Trump said he would name a successor within the next few weeks, and didn't directly answer a question about why he chose today to announce her resignation.

Six months ago, Haley shot back at a claim from Larry Kudlow, Trump's top economic advisor, that she was confused when she announced a new round of sanctions on Russia that never materialized. "With all due respect, I don't get confused," Haley said on Fox News in April.

Haley's initial conversation with Trump about resigning coincided with the appointments of Mike Pompeo as secretary of state and John Bolton as national security adviser, a White House official told the Associated Press. Pompeo and Bolton, who served as U.N. ambassador for less than a year as a recess appointment under President George W. Bush, have quickly become the loudest voices pushing Trump's foreign policy.

Haley was nothing but complimentary to Trump at the White House on Tuesday, telling reporters it was "the honor of a lifetime" to serve as U.N. ambassador and declined speculation that she was resigning to run against Trump in the 2020 presidential election.

"No, I'm not running for 2020. I can promise you what I'll be doing is campaigning for this one," Haley said, pointing at Trump. "I look forward to supporting the president in the next election."

Though the timing of the announcement caused many reporters and pundits to scratch their heads, Haley reportedly wanted to make her decision known prior to the midterm elections, in order to avoid embarrassing Trump if the results don't go his way.

Haley also praised Ivanka Trump and Jared Kushner, the president's son-in-law, telling reporters that both do a number of things behind the scenes that she wished more people knew about. "Jared is a hidden genius that no one understands… We're a better country because they're in this administration."

Haley's resignation was first reported by Axios' Jonathan Swan, who wrote that Haley discussed it with Trump last week during a visit to the White House, which "shocked a number of senior foreign policy officials" within the administration.

"I've been texting with congressmen on the Hill, both Democratic and Republican, and the one uniform response I've heard from them is surprise – they did not see this coming," said CNN chief national security correspondent Jim Sciutto.

"Nikki Haley has been a clear, consistent, and powerful voice for America's interests and democratic principles on the world stage. She challenged friend and foe to be better. I am saddened that she is leaving the administration, but so grateful for her service," Speaker of the House Paul Ryan (R., Wisc.) said in a statement.

Democratic Sen. Bob Menendez of New Jersey, the ranking member on the Senate Foreign Relations Committee, thanked Haley for her willingness "to express moral clarity to the world and to President Trump," and said he was concerned about the impact her sudden departure could have on national security.

"Today's announcement that Ambassador Haley is resigning is yet another sign of the Trump Administration's chaotic foreign policy and setback from promoting American values and priorities," Menendez said in a statement.

Haley, the former governor of South Carolina who drew attention for calling for the removal of the Confederate flag following a 2015 massacre at a black church in Charleston,  was sworn in as U.N. ambassador just four days after Trump's inauguration in 2017.