Guatemala's Congress has sworn in former judge Alejandro Maldonado as president, as his disgraced predecessor was detained over corruption allegations.
Maldonado, a 79-year-old conservative who only became vice president in May, will serve out the rest of his former boss Otto Perez's term, which ends on January 14.
The country will hold elections on Sunday (local time) to choose his successor, in a climate of widespread outrage over the corruption scandal engulfing Perez.
"The new government must emerge from the need to inspire citizens' confidence," said Maldonado, a lawyer and former judge on the Constitutional Court, after taking the oath of office.
Congress had earlier voted unanimously to accept Perez's resignation, which he submitted just before midnight on Wednesday, after lawmakers stripped him of his presidential immunity and a judge issued a warrant for his arrest.
As Maldonado was donning the blue-and-white presidential sash, Perez appeared before the Supreme Court, looking uncomfortable as prosecutors detailed their accusations against him.
"I'm calm and I will face the situation bravely because I've done nothing wrong," Perez said before his court appearance, where he sported a dark suit, red tie and a haggard look on his face.
The Supreme Court judge ordered the detention of Perez, saying he posed a flight risk and that he should be held at the Matamoros military prison near the centre of Guatemala City.
Investigators believe the 64-year-old conservative received US$3.7 million in bribes paid by importers in exchange for illegal discounts on their customs duty.
His former vice president Roxana Baldetti, who resigned in May, has already been charged with taking US$3.8 million in bribes between May 2014 and April 2015.
Guatemalans fed up with corruption erupted in celebration outside the Supreme Court on the news of Perez's resignation.
"Otto, you thief, you're going to Pavon!" they chanted, referring to one of the country's main prisons.
The scandal was uncovered by United Nations investigators tasked with fighting high-level graft in Guatemala.
They claim to have found evidence that Perez orchestrated a scheme dubbed "La Linea" (The Line), named after the hotline that importers would allegedly call to access a network of corrupt officials.
Investigators say their accusations are based on 89,000 wire-tapped phone calls.
The climate in Guatemala is jubilant but tense heading into Sunday's elections, which will also choose the members of the 158-seat legislature and 338 mayors.
UN Secretary-General Ban Ki-moon called on Guatemalans "to ensure that the upcoming elections are held in a peaceful environment".
Meanwhile, the US State Department expressed its "support for Guatemala's democratic and constitutional institutions", and said US leaders "stand ready to work with Vice President Maldonado in his new capacity".