LIMA, Peru — After less than two years in office, Peru’s embattled president, Pedro Pablo Kuczynski, offered his resignation on Wednesday, a day after the release of videos that showed key allies trying to buy the support of opposition lawmakers.

The tapes suggested that his allies had offered, among other enticements, lunches with the president, the authority to appoint government officials, expedited public works and even the chance to keep some public money.

For Mr. Kuczynski, the resignation appeared an effort to avoid the embarrassment of being fired by Congress, which had scheduled an impeachment vote for Thursday and seemed all but certain to oust him. Several of Mr. Kuczynski’s own supporters had called for his resignation after the secretly recorded video had been released.

However, Congress could refuse the resignation, and vote to impeach him anyway. There is a precedent: Alberto K. Fujimori resigned by fax after fleeing to Japan in 2000, but Congress rejected it and impeached him instead.

“Given this difficult situation that has been created, which unjustly makes me seem guilty of acts I have not participated in, I think that the best for the country is that I resign the presidency, because I don’t want to be an obstacle for our nation as it finds the path tu unity and harmony that it needs so much, and that I was denied,” Mr. Kuczynski said in a recorded address.

Mr. Kuczynski said the leaked recordings had been edited in a “selectively biased way that gave the impression that the government was offering public works in exchange of votes.”

Mr. Kuczynski was imperiled last year as well, narrowly averting a congressional ouster in December by granting a medical pardon to Mr. Fujimori, the former strongman . The move bought him the implicit support of Mr. Fujimori’s son Kenji, who is a member of Congress.

But on Wednesday, a series of short tapes showed Kenji Fujimori and his aides engaging in new political arm-twisting, offering cash in exchange for political benefits for their constituencies. The tapes appeared to have caused nearly fatal political damage to both the younger Mr. Fujimori and Mr. Kuczynski.

Mr. Kuczynski will be replaced by his vice president, Martín Vizcarra, who is also serving now as ambassador to Canada. Mr. Vizcarra himself was once forced by Congress to resign when he served in Mr. Kuczynski’s cabinet, although opposition lawmakers have in recent weeks spoken highly of him. Mr. Vizcarra has not spoken publicly about the controversy, and it was not clear on Wednesday whether he was even in Peru.

“This was a government that carved its tomb from Day 1,” said Eduardo Dargent, a political scientist at the Pontifical Catholic University of Peru. “Looking forward, it’s very unclear what will happen.”

Mr. Kuczynski, a former Wall Street banker and World Bank economist who was educated at Oxford and Princeton, campaigned in 2016 on a liberal platform that promised economic growth and “social revolution.” He narrowly beat Keiko Fujimori, the daughter of the former leader.

Last year, Congress accused Mr. Kuczynski of “permanent moral incapacity” for profiting from contracts with Odebrecht, the Brazilian corporate giant now beset by scandal, during a period in the early 2000s when he served as a cabinet member. Mr. Kuczynski said he was merely a shareholder in a company that profited from Odebrecht deals.

Congress’s impeachment effort had been enthusiastically supported by the Popular Force, the party led by Ms. Fujimori.

But in December, Mr. Kuczynski avoided removal thanks to Ms. Fujimori’s brother, Congressman Kenji Fujimori, who split with his sister and carried enough lawmakers to his side to save the president. That left Kenji Fujimori in a bitter fight with his sister, and Mr. Kuczynski in the middle. Two days after the failed ouster, Mr. Kuczynski pardoned Alberto Fujimori on medical grounds.

In the end, Mr. Kuczynski intertwined his fate with that of the Fujimori family. And while Kenji Fujimori saved Mr. Kuczynski last year, the effort to rescue him a second time ultimately led to a much more dramatic fall. The videos were recorded by Moisés Mamani, an ally of Keiko Fujimori who pretended to be toying with the idea of switching sides, but then recorded his conversations with Kenji, and released them at a news conference called by her party.

“I feel sorry about this, but this is the end that Mr. Kuczynski deserves,” said Pedro Cateriano, a former prime minister who counseled the president during the first impeachment attempt. “While the Fujimoris participate in our political life, democracy will be under threat.”

Kenji Fujimori called the recording of the tapes a “criminal act,” but their release left a sense of déjà vu here.

Almost 18 years ago, Alberto Fujimori was forced to call for new elections after videos showed his top adviser buying the support of opposition lawmakers with cash. He fled to Japan and resigned by fax.

On Wednesday, a series of short tapes showed Kenji Fujimori and his aides in a similar act of political arm-twisting.

“Those who voted in favor of ousting him, they have all seen the doors shut on them,” Mr. Fujimori can be heard telling Mr. Mamani in one of the videos.

In another video, Congressman Bienvenido Ramírez bragged about all the benefits he had received because of his support of Mr. Kuczynski.

“In less than a week I got the public works” that I wanted,” Mr. Ramírez told Mr. Mamani, who also mentioned a government official had been assigned to help expedite any projects that were in his interest.

Another government official tried to explain to Mr. Mamani how to earn big rewards while in Congress.

“Imagine, brother, that in a $100 million public work that you receive only 5 percent,” said Freddy Aragón, a government official who was fired last night. “Brother, you get $5 million without lifting a finger.”

Mr. Mamani had also recorded a conversation with Mr. Kuczynski’s personal lawyer, Alberto Borea, who said he’d help him get in touch with Bruno Giuffra, the minister of transportation and communications, and handed him his cellphone.

In another recording, Mr. Giuffra tells Mr. Mamani that the president is waiting for them at 7 p.m., gives him directions to his private address and tells him to hurry.

“You have to say ‘I’m not convinced and the truth is that my constituents don’t want impeachment.’” Mr. Giuffra tells Mr. Mamani, apparently coaching him on the talking points he should hit when he declared he had switched his vote.

Mr. Giuffra added: “Don’t even open your mouth about me, everything collapses if that’s the case.”