Nikki Haley has resigned as the US ambassador to the United Nations and will leave her post in January, in a move that stunned allied diplomats and other senior officials.

Haley and Donald Trump announced her departure in the Oval Office. The timing came as a surprise to her colleagues at the state department and at the UN security council.

The president and the outgoing envoy heaped praise on each other, to emphasise that she was not leaving on hard terms.

Haley portrayed her departure as the act of a conscientious public servant. “I think you have to be selfless enough to know when you step aside and allow someone else to do the job,” she said.

Asked about Haley’s successor, Trump said there were “a number of people that would very much like to do it”, saying Haley had made it “a more glamorous position”.

Early speculation that Ivanka Trump might step into the role appeared to be shut down by a tweet by the president’s daughter, saying she would not take the job.

Trump told reporters on the way to a rally in Nebraska that he had a shortlist of five contenders to replace Haley.

Donald Trump pushes Ivanka's suitability for UN ambassador role - video

﻿The only name on the list he mentioned was his former deputy national security adviser Dina Powell, who spent last weekend with Haley and their families on a boat in South Carolina. “Dina would love it,” he said.

Richard Grenell, the US ambassador to Germany who spent eight years at the mission to the UN, has been tipped as a contender by conservative commentators. Trump said Grenell was not his shortlist, but was willing to consider him.

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

The secretary of state, Mike Pompeo, and the national security adviser, John Bolton, are reported to have been taken unawares. But the president claimed he had been informed well in advance.

Trump said: “She told me probably six months ago. She said: ‘You know, at the end of the year, at the end of a two-year period, I want to take some time off, I want to take a break.’”

It is unclear why Haley made the announcement before the midterm elections.

She rejected speculation that she was leaving to take a run at the presidency, saying she had no plans to stand in 2020 and would be campaigning for Trump. In her resignation letter, published by the Washington Post, Haley said she was going back to the private sector, though she said she expected to “speak out from time to time on important public policy matters”.

The resignation letter was dated 3 October, the day after Trump appeared at a political rally in Mississippi and mocked Dr Christine Blasey Ford, who had accused Trump’s nominee for the supreme court of sexual assault. Haley has portrayed herself as a defender of women’s rights, though there is no evidence Trump’s derision of Ford was the immediate trigger for her decision.

﻿A former governor of South Carolina, Haley has been one of Trump’s most high-profile lieutenants, acting as the international face of the administration. However, she pursued an outspoken policy direction that was sometimes at odds with the White House, particularly on the subject of Russia.

While Trump has been reticent about criticising the Kremlin, Haley was a persistent, trenchant critic of Russian policy in Syria and Ukraine, and over the chemical weapon attack against a former Russian spy in the UK in March. In April she was humiliated when she announced imminent sanctions only to be contradicted by the White House which suggested she had been suffering from “momentary confusion”.

Haley fired back icily: “With all due respect, I don’t get confused.”

She also spoke out on human rights issues more frequently and fervently than others in the state department.

On other issues – unconditional support for Israel (the Israeli army took the unusual step of tweeting thanks for her “service”), unflinching hostility to Iran, North Korea and Venezuela – she was the most articulate exponent of hardline positions.

Earlier this year, she announced that the US was withdrawing from the United Nations human rights council, which she described as a “cesspool of political bias”.

The timing of Haley’s departure caught diplomats at the UN by surprise. She appears not to have given any indication of her intentions to colleagues on the security council.

But few of the diplomats she worked with expected her to stay in the UN role for the full four years of Trump’s presidential term. She was universally seen as a politician using the UN post to burnish her image and bide her time while it served her presidential ambitions.

“I thought she would go after two years, but two years isn’t up. Why would she go before the midterms?” a senior diplomat said.

The diplomat speculated she could have her eye on a South Carolina Senate seat, or that her departure could have been influenced by recent demands for an enquiry into her use of private jets last year provided by a South Carolina businessman, but expressed doubt over whether the allegations were serious enough to trigger an early departure.

Her departure will raise anxiety levels for US allies at the UN. Despite her pointed rhetoric – warning any country who voted against the US that she was “taking names” – she succeeded in convincing Trump that the UN served a useful purpose for US national interests.

However, her relative position within the administration had been diminishing since the arrival of Pompeo at the head of the state department. Under Pompeo’s predecessor Rex Tillerson, Haley had a free hand, as Tillerson took a low-key approach to his job and was frequently at odds with Trump, who often ignored him.