1 of 6
Moises Castillo, Associated Press
In this Monday, Aug. 31, 2015 photo, Guatemala's President Otto Perez Molina waves at the end of a press conference in Guatemala City. The president's spokesman Jorge Ortega says Molina has resigned in the face of a fraud scandal. Ortega says Perez Molina submitted his resignation at midnight local time late Wednesday, Sept. 2, 2015, after a judge issued an order to detain him in a corruption scandal that has brought his government to the brink.

GUATEMALA CITY — Guatemalan President Otto Perez Molina has resigned in the face of a corruption scandal that has brought his government to the brink, a spokesman said early Thursday.

Spokesman Jorge Ortega said Perez Molina submitted his resignation at midnight Wednesday local time after a judge issued an order to detain him in the customs fraud case, which already has led to the jailing of his vice president, and the resignation of several cabinet ministers who withdrew their support for the president.

His resignation, the first by a Guatemalan president, is not effective until members of Congress accept it and name a new president. They were convening early Thursday morning to do so.

Security was tight around the courthouse where Perez Molina was to appear Thursday morning, with scores of police and members of the presidential guard stationed around the building. The former president was expected to arrive at around 8 a.m. local time (10 a.m. EDT).

A growing protest movement brought together Guatemalans from all walks of life demanding that Perez Molina step down. Business leaders and even Catholic church officials had called for Perez Molina to resign in recent weeks as the investigation of the customs fraud ring has grown wider and hit more officials.

Perez Molina was steadfast in his plan to stay until the judge's unprecedented order, dealing the most serious blow yet to entrenched political corruption in the Central American country.

Ortega told reporters that in the end, Perez Molina submitted his resignation "to maintain the institution of the presidency and resolve on his own the legal proceedings leveled against him."

Perez Molina, 64, has maintained his innocence.

Vice President Alejandro Maldonado is constitutionally in line to assume the presidency. Maldonado, a conservative lawyer and former Constitutional Court judge, was chosen to replace former Vice President Roxana Baldetti, who resigned May 8 because of the same scandal and is now jailed and facing charges. She too maintains her innocence.

Maldonado would likely remain in office until the winner of upcoming elections is inaugurated Jan. 14, 2016. The first round is on Sunday, pitting a wealthy businessman and politician against 13 other candidates, including a comedian with no political experience, a former first lady and the daughter of an ex-dictator accused of genocide. If none of the candidates reaches 50 percent, a runoff will be held Oct. 25.

The country's reaction was initially quiet as the news played out in the middle of the night.

On Thursday morning, dozens of

The order to detain Perez Molina is not for his arrest, rather to for him to declare before Judge Miguel Angel Galvea, who granted the request Wednesday from Attorney General Thelma Aldana.

The president will have to appear on accusations of illicit association, fraud and receiving bribe money.

No formal charges have been filed, though Aldana said there is a preliminary investigation under way into the president's possible involvement in the fraud ring.

The president's attorney, Cesar Calderon, told The Associated Press that Perez Molina will appear voluntarily as soon as they have confirmed the order was issued.

Perez Molina was already under order not to leave the country, and on Tuesday congress lifted his immunity from prosecution.

The corruption scandal, uncovered by prosecutors and a United Nations commission probing criminal networks in Guatemala, involved a scheme known as "La Linea," or "The Line," in which businesspeople paid bribes to avoid import duties through the customs agency. The ring is believed to have defrauded the state of millions of dollars.

Baldetti's former personal secretary was named as the alleged ringleader.

Protesters have filled the streets almost daily over the scandal, demanding not only that Perez Molina step down but that next Sunday's presidential elections be postponed. He says delaying the vote would be against the law.

The U.N.'s International Commission Against Impunity said in a report released in mid-July that the country's elections are rife with illegal money and corruption is the glue holding the system together. Political parties consistently spend far more money than they report taking in and several regularly exceed spending limits without consequence.