LIMA (Reuters) - Anti-graft prosecutors in Peru on Wednesday asked a judge to bar President Pedro Pablo Kuczynski from leaving the South American country hours after he announced his resignation in the face of near-certain impeachment, a judiciary source told Reuters.

Kuczynski, a 79-year-old former Wall Street banker who once held U.S. citizenship, is guaranteed presidential immunity from prosecution until Congress formally accepts his resignation and Vice President Martin Vizcarra is sworn in to replace him.

Luis Galarreta, the president of Congress, said that would probably happen on Friday.

Kuczynski denies wrongdoing and has promised to cooperate with a graft probe into his connections to Odebrecht, a Brazilian construction company that has acknowledged bribing officials across Latin America.

The rightwing opposition party that controls Congress, Popular Force, first sought to force Kuczynski from office in December after revealing he failed to disclose payments Odebrecht made to his Flordia-based consulting firm while he held public office in a previous government.

Kuczynski had vowed not to resign for months, blaming the rightwing opposition for constant scandals that he said had made it impossible for him to govern Peru, one of Latin America’s most stable markets and the world’s No. 2 producer of copper.

But secret audio and video recordings released this week ensnared Kuczynski in vote-buying allegations that prompted even his staunchest supporters to demand he step down.

Kuczynski said the material, in which his allies are heard offering access to lucrative public work contracts in exchange for political support, had been edited as part of a relentless campaign to malign him.

But the hostile political climate had become untenable, he added.

“I think what’s best for the country is for me to resign...I don’t want to be an obstacle for the nation’s search for a path to unity and harmony,” Kuczynski said in a pre-recorded video televised as he was driven from the presidential palace to his home in Lima’s financial district.

MARKETS RALLY

Kuczynski’s announcement marked a spectacular downfall for a man elected less than two years ago amid hopes he would turbocharge growth while cleaning up government corruption and modernizing the Andean nation of about 30 million people.

Markets that had cheered Kuczynski’s rise to power in 2016 rallied on news of his departure on Wednesday, amid expectations it would end the political uncertainty that had loomed over the nearly $200-billion economy, just as higher copper prices were reviving investor interest.

Peru’s sol currency gained 0.5 percent against the dollar on Wednesday, and stocks closed up 1 percent.

But Kuczynski’s future looked less bright.

Prosecutors in a special anti-corruption unit in the attorney general’s office told a judge Kuczynski should not be allowed to leave the country, the judiciary source said, speaking on condition of anonymity.

Kuczynski said as a candidate in 2016 that he had renounced his U.S. citizenship in order to launch his bid. Last month, U.S. Ambassador to Peru Krishna Urs declined to confirm that Kuczynski no longer had citizenship.

Slideshow ( 22 images )

Kuczynski’s office did not immediately respond to requests for comment.

TRUMP TO HEAD TO PERU

Peru has a history of jailing former presidents, and of presidents fleeing.

Former authoritarian president Alberto Fujimori fled Peru for his parents’ native Japan as his decade in power ended in a corruption scandal and protests.

Slideshow ( 22 images )

Last year, former president Ollanta Humala, Kuczynski’s predecessor, was ordered up to 18 months in pre-trial detention while prosecutors prepare charges related to Odebrecht.

Kuczynski had been scheduled to welcome Donald Trump on the U.S. president’s first visit to Latin America next month, when many regional leaders plan to pressure Venezuelan President Nicolas Maduro to pursue democratic reforms.

Kuczynski, who called Maduro a “dictator” in an interview with Reuters last year, had led regional criticism of his government while opening the door to Venezuelan migrants fleeing the country’s economic crisis.

A White House official, speaking on background, said Trump still plans to attend the summit and declined to comment on Peru’s domestic political situation.

Instead of Kuczynski, Trump will meet Vizcarra at the Summit of the Americas that Peru will host on April 13 and 14.

A former governor of a mining region, Vizcarra once helped broker Anglo American Plc secure community support for its copper project, Quellaveco, and has served as Peru’s ambassador to Canada since September.

But Vizcarra will take office amid widespread demands for change after constant political crises and corruption scandals have eroded trust in institutions and political leaders.

Vizcarra took to Twitter from Canada to call for unity.

“I’m outraged by the current situation, like the majority of Peruvians,” Vizcarra said in his first public comments since Kuczynski announced his resignation. “But I’m convinced that together we can show that we can once more push forward.”

In recent days, Vizcarra has received public assurances from opposition lawmakers that they will let him govern, something Kuczynski said he had been denied.

“I’ve worked for nearly 60 years of my life with complete honesty,” Kuczynski added. “The opposition has tried to depict me as a corrupt person.”