Joaquín Guzmán Loera, the Mexican drug lord known as El Chapo, in federal custody on Long Island in 2017. Guzmán was sentenced on July 17 to life in prison.

NEW YORK — Joaquín Guzmán Loera, the Mexican drug lord known as El Chapo, was sentenced Wednesday to life in prison, ending one of modern history’s most brutal and notorious criminal careers.

The life sentence, mandated by law as a result of the severity of Guzmán’s crimes, was handed down in the U.S. District Court in Brooklyn, where the kingpin was convicted last winter of drug, murder and money laundering charges after a three-month trial.

As some of the federal agents who had chased him for years looked on from the gallery, Judge Brian M. Cogan issued the life term and Guzmán, 62, was hauled away to prepare himself — pending an appeal — for spending the rest of his life behind bars.

Cogan said the “overwhelming evil” of Guzmán’s crimes were apparent. Besides giving him a life sentence plus 30 years, he ordered the drug lord to pay $12.6 billion in restitution.

Speaking for several minutes before his sentencing, Guzmán said he had not received a fair trial and complained about his imprisonment in a federal jail in Manhattan, calling it “psychological, emotional and mental torture 24 hours a day.”

Guzmán almost certainly will be sent to the country’s most forbidding federal prison, the U.S. Penitentiary Administrative Maximum Facility, or ADX, in Florence, Colorado.

Guzman’s career atop one of Mexico’s most powerful cartels came to a close only after Mexico agreed to extradite him to the United States in January 2017.

His ability to escape from prison and evade capture for years underscored the deep corruption of Mexican authorities by his cartel, which employed bribery and intimidation to control not just local police departments but also the highest-ranking officials in the national government.

“It’s justice not only for the Mexican government, but for all of Guzmán’s victims in Mexico,” said Raymond P. Donovan, the agent in charge of the New York office of the Drug Enforcement Administration, which was instrumental in capturing the kingpin twice.

Prosecutors presented evidence that he sent hundreds of tons of drugs to the United States from Mexico and caused the deaths of dozens of people to protect himself and his smuggling routes.

The verdict Feb. 12 came after more than a week of deliberations by the jury. Ultimately, Guzmán was found guilty on all 10 counts of the indictment.

As the verdict was read, he sat listening to a translator, looking stunned. When the reading of the verdict was complete, Guzmán leaned back to glance at his wife, Emma Coronel Aispuro, who flashed him a thumbs up with tears in her eyes.

On that day, Richard P. Donoghue, the U.S. attorney for the Eastern District of New York, called the guilty verdict a victory for law enforcement.

“There are those who say the war on drugs is not worth fighting,” Donoghue said. “Those people are wrong.”

Even Guzmán’s lawyers admitted defending the kingpin was a daunting task.

“I’ve never faced a case with so many cooperating witnesses and so much evidence,” said Jeffrey Lichtman, one of Guzmán’s lawyers. “We did all we could as defense lawyers.”