Washington • U.N. Ambassador Nikki Haley is resigning, she and President Donald Trump announced Tuesday, blindsiding many administration officials and stirring speculation in the White House and beyond about the timing and reasons for the latest Trump shake-up just weeks before the November midterm elections.

The news was news to many congressional Republicans involved in foreign policy matters, and some key U.S. allies did not get advance word from Haley or the White House. Neither she nor Trump gave any specific reason.

"I have given everything I've got these last eight years," she said, referring to her six years as South Carolina governor as well as her time at the U.N. "And I do think it's good to rotate in other people who can put that same energy and power into it."

There has been speculation that Haley, one of the highest-profile women in the administration, will return to government or politics at some point.

"No, I'm not running in 2020" for president, she joked, quickly adding that she would be supporting Trump.

The decision to announce the latest shake-up came less than a month before the elections, even as the White House has made a concerted effort to hold off on major changes — at the Justice Department and elsewhere — before then.

Trump was asked why the announcement was made now since Haley is staying until the end of the year.

Instead of answering directly, he recounted how she has had to work on tough issues, such as Iran and North Korea.

White House officials had sought to put a hold on record-setting administration turnover in the run-up to the Nov. 6 elections, with aides being asked months ago to step down or commit to stay through Election Day to avoid adding to a sense of turmoil.

Still, the prospect of post-midterm changes has loomed over the West Wing, and Haley's exit was one of those discussed, according to a senior administration official not authorized to publicly discuss private conversations.

Despite Trump's calm words, her sudden announcement rattled a number in the White House, who openly speculated that the timing was meant to preserve the ambassador's own political future, according to the official and another White House official.

Trump said Haley first discussed leaving the administration with him six months ago. The official noted that their conversation coincided with the appointment of Mike Pompeo as secretary of state and John Bolton as national security adviser. Haley had expressed some frustration that her voice had been diminished as the two men became the aggressive new faces of Trump's foreign policy, the official said.

More recently, there was an awkward moment at the U.N., when Trump's boasting of American economic strength under his leadership drew laughter at a General Assembly session. He insisted later that the delegates were laughing with him, not at him.

The six-month timeline also coincides with a high-profile spat between Haley and the White House in April, when she drew the president's ire for previewing in a television appearance the administration's planned imposition of a new round of sanctions on Russia. When the sanctions never materialized, White House officials said the plans had changed without Haley being briefed, and top economic adviser Larry Kudlow suggested Haley was confused.

"I don't get confused," Haley said in a sharply-worded rejoinder to the West Wing.

Haley, 46, was appointed to the U.N. post in November 2016 and last month coordinated Trump's second trip to the United Nations, including his first time chairing the Security Council.

A rookie to international politics, the former South Carolina governor was an unusual pick for to be U.N. envoy. At the U.N., she helped spearhead the administration's efforts to combat what it alleged to be anti-American and anti-Israel actions by the international body, and address U.S. tension with its European allies and with Iran and North Korea.

"It was a blessing to go into the U.N. every day with body armor," Haley said, saying her job was to defend America on the world stage.

Trump said he was considering many candidates for Haley's job and that a successor would be named in two to three weeks — or maybe sooner.

Last month Haley wrote an op-ed article in The Washington Post discussing her policy disagreements but also her pride in working for Trump. It came in response to an anonymous essay in The New York Times by a senior administration official that alleged there to be a secret "resistance" effort from the right in Trump's administration and that there were internal discussions of invoking the 25th amendment to remove him from office.

"I proudly serve in this administration, and I enthusiastically support most of its decisions and the direction it is taking the country," Haley wrote. "But I don't agree with the president on everything."

The daughter of Indian immigrants, Haley clashed with then-candidate Trump during the 2016 campaign, denouncing "the siren call of the angriest voices" that disrespected America's immigrants. Trump tweeted that "The people of South Carolina are embarrassed by Nikki Haley."

"Before she was named by Trump to her U.N. post, Haley was elected the first female governor of South Carolina. She was re-elected in 2014. As governor, she developed a national reputation as a racial conciliator who led the charge to bring down the Confederate flag at the Statehouse and helped guide the state through one of its darkest moments, the massacre at a black church.

South Carolina Republican Sen. Lindsey Graham, a close Trump ally tweeted that Haley "has a very bright future and will be a key player in both the future of the Republican Party and our nation as a whole for years to come."

"I want to thank Ambassador Haley for her willingness to express moral clarity to the world and to President Trump, and promote American values and leadership on the global stage, even when she lacked the backing of the White House or State Department.

Sen. Bob Menendez of New Jersey, the ranking Democrat on the Senate Foreign Relations Committee, said Haley's leaving is "yet another sign of the Trump administration's chaotic foreign policy and setback from promoting American values and priorities." Menendez said he is concerned about the leadership vacuum she leaves and "the national security impact of her departure at this time of continued disarray for this administration."

___

Lemire reported from New York. Associated Press writers Matthew Lee in Washington, and Meg Kinnard in Columbia, South Carolina contributed to this report.