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 choas just 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.

The letter of resignation was signed late Wednesday and sent to the country’s Congress, presidential spokesman Jorge Ortega said.