Guatemalan President Otto Pérez Molina has resigned over corruption charges, and the country's Congress was due to hold an emergency session to hand power to the vice president.
President Pérez Molina, a 64-year-old retired general, was due to appear in court on Thursday to face corruption charges after he quit Wednesday evening in a scandal which gutted his government and plunged Guatemala chaos days before a national election.
"I face the corresponding (judicial) processes with a clear conscience," Pérez Molina wrote in his resignation letter to Congress. "My commitment to the people of Guatemala is to submit, with all integrity, to the due process of the rule of law and refute the accusations against me."
Thousands of protesters flooded the streets of the capital, Guatemala City, and other cities in recent weeks calling for Pérez Molina to quit over allegations for involvement in a customs racket.
Prosecutors allege Pérez Molina was involved in a customs scam dubbed "La Linea," or the line, after a phone hotline used by importers to avoid paying customs duties in exchange for bribes.
Congress was expected to meet on Thursday to hand power to Vice President Alejandro Maldonado.
Pérez Molina was elected in late 2011 on a ticket to combat crime and corruption. He was not constitutionally eligible to run for re-election in Sunday's presidential vote.
He has repeatedly denied any wrongdoing and had vowed repeatedly not to 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.
"It is a personal decision to maintain institutions and to face the case brought against him," Ortega said.
Prosecutors said the charges to be brought against Pérez Molina were illicit association, taking bribes and customs fraud.
Attorney General Thelma Aldana said on Wednesday that Pérez Molina was also being investigated for money laundering, which could lead to the freezing of his assets.
Pérez Molina, who had been deemed a flight risk, will present himself at court on Thursday morning, his lawyer said.
His conservative administration spent much of this year mired in public protests and scandals over corruption allegations against senior officials, several of whom he fired during a Cabinet purge in May.
Former vice president Roxana Baldetti resigned after she was linked to "La Linea." She denied any wrongdoing but was arrested on the same charges Pérez Molina now faces.
More than 20 other people have been arrested over the scam, though how much money was involved is still unclear.
Prosecutors and a powerful U.N.-backed anti-corruption body known as the CICIG moved against Pérez Molina following months of investigations, and findings taken from some 89,000 telephone taps, almost 6,000 emails and 17 raids.
The anti-corruption investigations have also hit the center-right opposition Lider party, whose election candidate Manuel Baldizon is leading opinion polls.
No candidate is expected to win more than 50 percent of the vote on Sunday, triggering a second round run-off on Oct. 25. The next president will then formally take the helm in January.
(With reporting by Sofia Menchu and Enrique Andres Pretel; Writing by Christine Murray; Editing by Simon Gardner, John Stonestreet and W Simon)