President Otto Pérez Molina of Guatemala resigned on Thursday to face charges in a customs fraud scandal that has generated a sweeping protest movement of citizens enraged by government corruption.
In a letter to the president of Congress, Mr. Pérez Molina said that he was resigning to “face justice and resolve my personal situation.” Vice President Alejandro Maldonado is expected to become president for the remainder of Mr. Pérez Molina’s term, which ends in January.
The resignation was viewed as a victory for the rule of law in a country with a long history of impunity for the business and political elite. Networks of corruption have gone unpunished as powerful groups succeeded in turning the law to their own advantage.
But in a series of swift-moving events since prosecutors first accused Mr. Pérez Molina two weeks ago of leading the customs fraud scheme, his allies in the cabinet and the powerful business confederation deserted him, and street protests mounted. Then, on Tuesday, Congress voted to strip him of immunity from prosecution.
As late as Wednesday, after Attorney General Thelma Aldana announced that a judge had granted a warrant for his arrest, Mr. Pérez Molina’s lawyers were insisting that he would not resign. But overnight, he changed his mind.
It is still unclear if a judge will order his arrest or will order him to appear in court, which his lawyers have said he will do. The hearing could come as early as Thursday.
At the center of the events that led to Mr. Pérez Molina’s downfall is a persistent citizens movement that brought together vastly different groups for the first time. Guatemala City’s middle class, long reluctant to speak out after a brutal civil war demonstrated the costs of opposition, joined forces with peasant and indigenous groups.
The political turmoil comes three days before a general election scheduled for Sunday. Mr. Pérez Molina was not eligible for re-election, but many of the demonstrators who have filled the central square in Guatemala City, the capital, have been unsatisfied with the choices before them.
The leading candidate, Manuel Baldizón, a wealthy businessman, is widely seen as part of the same corrupt political system as the incumbent. His vice-presidential candidate faces charges in a separate corruption case, and Mr. Baldizón’s party had maintained a close alliance with Mr. Pérez Molina and his party.
Civic groups and academics had proposed postponing the vote, but they were blocked by the electoral tribunal.
If no candidate wins 50 percent on Sunday, the vote will move to a second round on Oct. 25. The other leading candidates are the comedian Jimmy Morales, who has moved up in the polls because he is seen as outsider, and Sandra Torres, a former first lady.
The political turmoil that led to Mr. Pérez Molina’s resignation began in April when prosecutors first revealed the existence of the customs fraud scheme, in which importers paid bribes in exchange for discounts on tariffs.
A panel of international prosecutors backed by the United Nations helped Ms. Aldana’s office develop the complex case using wiretaps and financial statements. To many observers, the work of the nine-year-old anticorruption panel has been essential to strengthening prosecutors and courts.
Although Mr. Pérez Molina was not directly named at the time, Guatemalans began to stage weekly protests to demand his resignation. His vice president, Roxana Baldetti, who was also linked to the scheme, resigned in May and was arrested two weeks ago.
Both deny any involvement.