A Mexican ex-prosecutor – who once declared himself a law-and-order candidate – was sentenced Thursday to 20 years in prison for using his position as attorney general to help protect a violent drug cartel, the Justice Department announced.

Speaking in the same Brooklyn courthouse where Mexican drug lord Joaquin "El Chapo" Guzman was sentenced to life earlier this year, Edgar Veytia, 49, told a judge he made a "mistake" by taking hundreds of thousands of dollars in bribes from the cartel while he was attorney general in the Pacific coast state of Nayarit.

Veytia – a dual U.S.-Mexico citizen who had lived off and on in San Diego – had pleaded guilty earlier this year to charges he helped the drug organization smuggle cocaine, heroin, and methamphetamine into the U.S. in exchange for bribes.

KIDNAPPED MEXICAN POLICE COMMANDER FOUND BEHEADED IN CANCUN

In their communications, Veytia and drug kingpin Juan Francisco Patron Sanchez used "processing" as code for "committing violent acts against rival drug traffickers detained by corrupt Mexican law enforcement officers controlled by the defendant," court papers said. After Patron Sanchez killed one of his enemies in 2015, Veytia even assisted in covering up the slaying, the papers said.

Other times, Veytia used wiretaps and conducted raids targeting rival drug gangs, the papers said. He also arranged for the members and associates of the cartel to be sprung from prison.

CLICK HERE FOR THE FOX NEWS APP

After surviving a 2011 assassination attempt, Veytia reportedly promoted himself as a law-and-order candidate while running for attorney general.

"Nayarit is not fertile ground for lawbreaking," he once said. "Here, there is no room for organized crime."

The Associated Press contributed to this report.