Guatemala’s highest court has overruled an order by President Jimmy Morales to expel the head of the UN anti-corruption mission in the country.
The Constitutional Court suspended the deportation order against Iván Velásquez, who backed an investigation into funding irregularities in the president’s 2015 election campaign.
Mr Morales had accused Mr Velásquez of interfering in domestic affairs.
The deportation order had been internationally criticised.
The UN has backed calls for the removal of Mr Morales’s immunity so he can be investigated.
The president announced the decision on Sunday in a video posted on social media, in which he declared the Colombian lawyer, who has been in the post since September 2013, persona non grata.
The Constitutional Court initially suspended the order and now has given its complete backing to the UN mission.
Mr Morales’s move created a crisis in the country, with at least eight high-level government officials resigning and two being sacked.
There have also been street protests with demonstrators demanding the president’s resignation.
Earlier, the UN’s human rights chief, Zeid Ra’ad al-Hussein, said he was disturbed by Mr Morales’s decision, while the US Ambassador to the UN, Nikki Haley, said the move was profoundly worrying.
The president now faces the possibility of being further investigated and, if stripped of his immunity, potential charges, BBC’s Central America correspondent Will Grant reports.
The UN mission was key in bringing bribery charges against the last president, Otto Perez Molina, who is currently in prison, our correspondent adds.
Mr Morales is a former comic actor who had never held public office before becoming president.
He surprised traditional politicians and won the 2015 election promising to tackle corruption and impunity.