Guatemala's president resigned early Thursday, hours after a judge ordered him to appear in court amid an ongoing investigation into a customs fraud ring involving members of his government.

Presidential spokesman Jorge Ortega told the Associated Press that Otto Perez Molina submitted his resignation at midnight local time.

Late Wednesday, Judge Miquel Angel Galvez ordered that Perez Molina, 64, be detained to answer accusations of illicit association, fraud and receiving bribe money. The unprecedented order is not for arrest, but for Perez Molina to declare before Judge Miguel Angel Galvea, who granted the request Wednesday from Attorney General Thelma Aldana, she told Canal Antigua television.

Perez Molina, 64, has maintained his innocence and vows to face the legal process. No formal charges have been filed, though Aldana said there is a preliminary investigation underway into the president's possible involvement in the 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.

It is the first time a sitting Guatemalan president has faced prosecution, though several have faced corruption charges after leaving office.

Perez Molina is under an order not to leave the country, and on Tuesday the country's congress lifted his immunity from prosecution.

The corruption scandal, uncovered by prosecutors and a U.N. 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.

The scandal has already claimed the job of former Vice President Roxana Baldetti, whose former personal secretary was named as the alleged ringleader. Baldetti resigned May 8 and is currently in jail awaiting trial on accusations she took millions of dollars in bribes.

She too says she is innocent.

Protesters fill 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.

Perez Molina is constitutionally barred from seeking re-election, and whoever becomes his successor would take office in January.

The Associated Press contributed to this report.