Guatemalan President Otto Perez has resigned, his spokesman said on Thursday, after becoming embroiled in a corruption scandal that has gutted his government and plunged the country into chaos days before a national election.
Thousands of protesters had flooded the streets of the capital, Guatemala City, and other cities in recent weeks calling for Perez, a 64-year-old retired general, to quit over allegations of involvement in a customs racket.
His letter of resignation was signed late on Wednesday and sent to the country's Congress, which was expected to hold an emergency session early on Thursday to hand power to Vice President Alejandro Maldonado in line with the constitution, presidential spokesman Jorge Ortega said.
Perez has repeatedly denied any wrongdoing and said he would not resign.
But his options narrowed on Wednesday when a judge issued a detention order against him after lawmakers voted to strip him of immunity from prosecution.
Prosecutors said the charges against Perez, who was elected on a ticket to combat crime and corruption, were illicit association, taking bribes and customs fraud.
Perez's lawyer said the president, who had been deemed a flight risk, would present himself at court at 8 a.m. on Thursday (1400 GMT).
Prosecutors allege Perez was involved in a customs racket dubbed "La Linea", or the line, after a phone hotline used by importers to avoid paying customs duties in exchange for bribes.
Perez is not constitutionally eligible to run for re-election in Sunday's presidential vote.