By Alexandra Alper and Sofia Menchu
GUATEMALA CITY (Reuters) - Guatemala's Otto Perez resigned his presidency and turned himself in to a court on Thursday to face charges in a corruption scandal that gutted his government and plunged the country into chaos days before a presidential election.
Congress, in an emergency session, approved the resignation of Perez, a 64-year-old retired general who quit overnight. Vice President Alejandro Maldonado will fill out the remaining months of Perez' term.
Thousands of protesters flooded the streets of the capital and other cities in recent weeks calling for Perez to step down over allegations he was involved in a customs racket.
"I have submitted to (judicial) processes so that Guatemala can move on and so that there is no violence or bloodshed," Perez said in a local radio interview on Thursday.
In his resignation letter to Congress, Perez said he would face the charges against him "with a clear conscience."
"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," he wrote.
Prosecutors allege Perez was involved in a customs scam dubbed "La Linea," ("The Line") after a phone hotline used by importers to avoid paying customs duties in exchange for bribes.
The celebrations over Perez' resignation erupted in a plaza of the capital days before Sunday's presidential and congressional elections.
"At last, the most corrupt president in the history of Guatemala is gone," said Juan Carlos Carrera, a 38-year old lawyer who waved a blue and white Guatemalan flag from his car window and honked his car horn.
"This is a citizens' revolution, because Guatemala has been divided for many years with so much injustice," he said.
Dressed in a dark suit, Perez sat in a courtroom, where prosecutors played phone recordings that allegedly implicate him in the scandal. A judge was expected to decide whether there is enough evidence to jail Perez as he awaits trial.
The White House said it respected Perez' decision to resign, and added that the Obama administration was ready to work with Vice President Alejandro Maldonado in his new role.
"We commend the people of Guatemala and their institutions for the manner in which they have dealt with this crisis, and continue to underscore our support for Guatemala's democratic and constitutional institutions," White House spokesman Josh Earnest told reporters.
Perez 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 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.
Prosecutors said the charges to be brought against Perez were illicit association, taking bribes and customs fraud.
Attorney General Thelma Aldana said on Wednesday that Perez was also being investigated for money laundering, which could lead to the freezing of his assets.
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 Perez now faces.
More than 20 other officials, including the president of the central bank, 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 Perez 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, has been leading the polls.
However, independent challenger Jimmy Morales, a comic actor, has edged ahead, according to one poll published on Thursday.
Morales was supported by 25 percent of likely voters, with Baldizon trailing at 22.9 percent, according to the survey from polling firm Prodatos.
Leftist candidate Sandra Torres had 18.4 percent of the poll, which had a margin of error of 3.1 percent. About 18 percent of voters were still undecided.
If no candidate wins more than 50 percent of the vote on Sunday, the top two candidates will face off in a second round on Oct. 25. The next president will formally take the helm in January.
(With reporting by Sofia Menchu and Enrique Andres Pretel; Writing by Christine Murray and Michael O'Boyle; Editing by Simon Gardner, W Simon and Dan Grebler)