“The message was that Mr. Guzmán didn’t have to stay in hiding?” Mr. Lichtman asked.

“Yes,” Mr. Cifuentes said, “that very thing is what Joaquin said to me.”

Mr. Lichtman, quoting Mr. Cifuentes’s notes from an interview he gave to American authorities in 2016, asked whether Felipe Calderón, who preceded Mr. Peña Nieto as Mexico’s president, took a bribe in 2008 from one of Mr. Guzmán’s rivals, the Beltrán-Leyva brothers.

“I don’t recall this incident very well,” Mr. Cifuentes answered. He added moments later, “Right now, I do not remember that.”

Mr. Peña Nieto and Mr. Calderón could not yet be reached for comment.

While other witnesses at Mr. Guzmán’s trial in Federal District Court in Brooklyn have testified about huge payoffs from traffickers to the Mexican police and public officials, the testimony about Mr. Peña Nieto was the most egregious allegation yet. If true, it suggests that corruption by drug cartels had reached into the highest level of Mexico’s political establishment.

After testifying about the two presidents, Mr. Cifuentes rattled off other bribes that Mr. Guzmán and his allies had paid to Mexican officials. On at least two occasions, he said, the kingpin gave the Mexican military between $10 million and $12 million to launch operations to “either kill or capture” associates of the Beltrán-Leyva brothers during his war with them.

Mr. Cifuentes also said the Mexican federal police not only turned a blind eye to drug trafficking, but occasionally took part in it. Once, he told jurors, traffickers gave the police photographs of several suitcases packed with cocaine that were sent by the cartel on an airplane from Argentina to Mexico. The police picked up the suitcases from the baggage claim, Mr. Cifuentes said, and sold the drugs themselves.

All of this came on Mr. Cifuentes’s exhausting second day as a witness at Mr. Guzmán’s trial. He has already confessed to a staggering array of crimes.