Guatemalan president Otto Perez Molina has resigned in the face of a corruption scandal which has brought his government to the brink of collapse.

Mr Perez Molina submitted his resignation, according to spokesman Jorge Ortega, after a judge issued an order to detain him in a customs fraud case which has already led to the jailing of his vice president and the resignations of some cabinet ministers.

The judge's order was unprecedented, dealing the most serious blow yet to entrenched political corruption in the Central American country.

The order is not for arrest, but for Mr Perez Molina to appear before Judge Miguel Angel Galvea, who granted the request from chief prosecutor Thelma Aldana.

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

Mr Perez Molina, 64, has maintained his innocence and vows to face the legal process. No formal charges have been filed, though Ms Aldana said there is a preliminary investigation under way into the president's possible involvement in the fraud ring.

The president's lawyer Cesar Calderon said he will appear voluntarily as soon as it is 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.

Mr Perez Molina is under an order not to leave the country and congress this week lifted his immunity from prosecution.

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

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

She too says she is innocent.

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

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