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.

Mr. Kuczynski had spent months fighting off attempts to oust him, and he had vowed not to resign. But he faced an impeachment trial set for Thursday, which he appeared likely to lose, and the release of the videos made his decision inevitable.

Late last year, after Mr. Kuczynski had been accused of wrongdoing in an international graft scandal involving construction contracts, he pardoned former President Alberto Fujimori, who had been convicted of human rights violations. The pardon appeared to be part of a deal with one of Mr. Fujimori’s sons, a congressman who controlled enough votes to save Mr. Kuczynski from being removed from office at the time.

But it was the secretly recorded tapes — which appeared to show allies of Mr. Kuczynski’s soliciting support with offers of big rewards to lawmakers — that prompted his decision on Wednesday. Among the offers, according to the tapes, were lunches with the president, the authority to appoint government officials, expedited public works projects and even the chance to keep some public money.