He was one of the most notorious outlaws of the last 100 years: a brutal Mexican cartel leader, a wily trafficker who smuggled more than $12 billion worth of drugs and plunged his country into a long-running tragedy of bloodshed and corruption.

But on Wednesday morning, the 30-year criminal career of Joaquín Guzmán Loera, known to the world as El Chapo, reached its final chapter as a federal judge in New York City sentenced him to life in prison.

The life term, mandated by law as a result of the severity of Mr. Guzmán’s crimes, was handed down in Federal District Court in Brooklyn, where the kingpin was convicted last winter of drug, murder and money laundering charges after a sprawling 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 sentence and Mr. Guzmán, 62, was hauled away to prepare himself — pending an appeal — for spending the rest of his life behind bars.

Although Judge Cogan had no choice but to sentence Mr. Guzmán to life, he noted that the “overwhelming evil” of the drug lord’s crimes was readily apparent. Beyond the life sentence — plus an additional 30 years — he ordered him to pay a staggering $12.6 billion in forfeiture.

Looking disheveled and slightly out of sorts, Mr. Guzmán walked into the eighth-floor courtroom under guard shortly before 9:30 a.m. He wore a loosefitting gray suit, with his tie rakishly askew and a new-growth mustache darkening his upper lip.

Reading from a prepared statement, he said he had not received a fair trial and complained about his solitary confinement in Manhattan’s federal jail, calling it “psychological, emotional and mental torture 24 hours a day.”

“Since the government of the United States is going to send me to a prison where my name will never be heard again, I take advantage of this opportunity to say there was no justice here,” he said.

Though Judge Cogan did not specify where Mr. Guzmán would serve his sentence, he is likely to be sent to the country’s most forbidding federal prison, the United States Penitentiary Administrative Maximum Facility, or ADX, in Florence, Colo.

Mr. Guzmán’s decades-long career atop the Sinaloa drug cartel, one of Mexico’s most powerful criminal mafias, came to a close only after years of joint investigation and pursuit by the American and Mexican authorities.

His ability to persistently evade capture — and then escape from prison after he was caught — underscored the deep corruption of the Mexican government by his cartel, which used bribery and intimidation to control not just the local, state and federal police, but some of 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, who was instrumental in capturing the kingpin twice.

After the sentencing, one of Mr. Guzmán’s lawyers, Jeffrey Lichtman, spoke outside the courthouse in the Brooklyn Heights neighborhood, complaining, as his client had, that the lengthy legal proceeding had been unfair.

“All he wanted was justice and at the end of the day, he didn’t get it,” Mr. Lichtman said, adding, “It was a show trial, and it’s been so since Day 1.”

Moments later, Richard P. Donoghue, the United States attorney in Brooklyn, whose office prosecuted the case with colleagues from Miami and Washington, also addressed reporters.

Video

Joaquín Guzmán Loera, the drug lord known as El Chapo, was sentenced on Wednesday to life in prison plus 30 years.CreditCreditDrew Angerer/Getty Images

Mr. Donoghue said the authorities could not undo the misery Mr. Guzmán had caused, “but we can ensure that he spends every minute of every day of the rest of his life in prison.”

The trial took place under intense media scrutiny and tight security that involved bomb-sniffing dogs, police snipers and federal marshals with radiation sensors. The verdict on Feb. 12 came after more than a week of deliberations by the jury. Ultimately, Mr. Guzmán was found guilty on all 10 counts of the indictment.

Prosecutors leveled some of the most serious charges possible against him, presenting 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 case revealed in exacting detail the inner workings of the Sinaloa drug cartel, such as how it employed I.T. consultants and how it packaged its cocaine in rubber “condoms.”

But given the defendant’s fame and notoriety, the trial was also a boisterous legal circus, complete with a horde of international reporters, a steady trickle of curious “narco-tourists” and a cameo appearance by an actor who plays the drug lord on a Netflix show.

The American authorities began their hunt for the kingpin as far back as the early 1990s, when he was indicted on separate federal charges in Tucson and San Diego.

The two indictments were filed just before and somewhat after he was arrested while on the run in Guatemala and then returned to Mexico, where he was tried and imprisoned for the 1993 murder of Juan Jesús Posadas Ocampo, a beloved Roman Catholic cardinal.

In 2001, however, Mr. Guzmán broke out of prison — by many accounts, in the bottom of a laundry cart — and spent the next 13 years playing cat-and-mouse with the law.

He evaded both arrest and the five subsequent indictments filed against him in the United States, largely by shuttling among a series of hide-outs in the Sierra Madre mountains in the Mexican state of Sinaloa.

In February 2012, the Mexican and American authorities came within inches of nabbing him in an ocean-view mansion in Cabo San Lucas, Mexico.

Within a year and a half, however, he had escaped again — this time, through a sophisticated tunnel that opened into the shower of his prison cell. A coalition similar to the one that caught him in 2014 redoubled its efforts and captured the kingpin for a second time, after a violent gunfight, in Los Mochis, Mexico, in early 2016.

When Mr. Guzmán finally stood trial in New York in November, his conviction was all but assured given the mountains of evidence collected against him over the years.

Some of that evidence came from incriminating intercepts from the various wiretaps over which agents had for months been listening in on the kingpin and his underlings. But just as damaging were the 14 witnesses from inside his cartel — suppliers, distributors, top lieutenants, even one of his mistresses — who testified against him.

Since his extradition to the United States in January 2017, Mr. Guzmán has been held in 10 South, the maximum-security wing of the Manhattan federal jail. On Wednesday, he told Judge Cogan that since arriving there he had been forced to drink “unsanitary water” and wear earplugs made from toilet paper to drown out the racket of the ventilation system.

In response, Gina Parlovecchio, a federal prosecutor, said it was ironic that Mr. Guzmán had complained about undignified treatment in jail given that he showed no respect to his countless victims, not just those he killed or hunted, but the thousands who were harmed by the drugs he “pumped onto the streets,” earning him a vast fortune of “blood money.”

One of those victims, Andrea Velez, spoke out in court on Wednesday. She described through her tears how Mr. Guzmán had paid a Canadian chapter of the Hells Angels $1 million in a failed plot to murder her. Ms. Velez was at one point the personal assistant to one of the kingpin’s top lieutenants, Alex Cifuentes Villa, but eventually became an F.B.I. informant who spied on the drug lord and his allies.

Alan Feuer covers courts and criminal justice for the Metro desk. He has written about mobsters, jails, police misconduct, wrongful convictions, government corruption and El Chapo, the jailed chief of the Sinaloa drug cartel. He joined The Times in 1999. @alanfeuer

A version of this article appears in print on , Section A, Page 25 of the New York edition with the headline: Life Term and $12.6 Billion Fine End El Chapo’s Notorious Criminal Career. Order Reprints | Today’s Paper | Subscribe