NEW YORK — When Joaquín Guzmán Loera, the Mexican drug lord known as El Chapo, walks into court Wednesday and is sentenced, by law, to life in prison, it will likely close the book on a criminal career unparalleled in its scope and celebrity since Al Capone’s.

But as with everything in the Guzmán case, getting to the end was not an easy matter. And an epilogue or two (or three or four) may still need to be written.

Guzmán, 62, was convicted this winter after a three-month trial in U.S.District Court in Brooklyn that often veered, in head-snapping fashion, between solemnity and absurdity.

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 brutal 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 IT consultants and how it packaged its cocaine in waterproof 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.

At one point, there was even a bizarre marital stunt in which Guzmán and his third wife, Emma Coronel Aispuro, showed up in the courtroom wearing matching velvet smoking jackets.

Even after the guilty verdict was issued Feb. 12, the case did not let up. Two days later, federal prosecutors in Washington unsealed an indictment against two of Guzmán’s sons, Joaquín and Ovidio Guzmán López. A few days after that, one of the anonymous jurors in El Chapo’s case told a reporter for Vice Media that several of the panelists had disobeyed repeated orders by the judge not to follow media coverage of the trial.

The Vice article prompted Guzmán’s lawyers to submit a motion requesting a new trial. And for a period of weeks, it suddenly seemed possible that the jurors might be hauled back into court and the protracted case forced to continue with a hearing to determine if they had in fact committed misconduct.

But in early July, Judge Brian Cogan foreclosed that possibility, denying the new trial motion and moving things forward toward the sentencing.

Some of the witnesses who testified against Guzmán have themselves recently been sentenced. At the end of June, a federal judge in Texas gave a nine-year prison term to Edgar Galvan, a divorced man from El Paso who wound up running guns for one of Guzmán’s most feared assassins after meeting him one evening at a nightclub across the border in Ciudad Juárez, Mexico. And in late May, Vicente Zambada Niebla — the son of Guzmán’s partner and the cartel’s heir apparent — was sentenced in Chicago to 14 years in prison.

Around the same time, the assassin who befriended Galvan, Antonio Marrufo (or “the Jaguar,” as he called himself) was extradited from Mexico to Texas to face federal charges, including his alleged involvement in a brazen plot to kidnap a groom on his wedding day and kill him — and his best man — in Ciudad Juárez.

But it remains unclear for now where Marrufo’s prosecution might be headed given that more than a dozen sealed documents have been posted on his docket in the two months following his extradition.

A similar level of secrecy was applied to Guzmán’s case, although prosecutors in Brooklyn have started to unseal some of the filings. According to a document released two weeks ago, the kingpin, during one of his many wars against his rivals, hired a doctor to revive a man he had been torturing. After the victim regained consciousness, Guzmán and his crew kept working on the man, the document said, applying electrodes to his ear and yanking some of his teeth out.

Another document from early July revealed that the government had come up with a “conservative” estimate of Guzmán’s total career earnings: $12,666,181,704. They said they wanted him to pay it back.

Across the country, other cases related to Guzmán are slowly moving forward. Jesus Beltran Leon, a close associate of the kingpin’s sons, pleaded guilty to drug charges in April and will soon be sentenced in Chicago.

One of Guzmán’s top security chiefs, José Rodrigo Aréchiga, known as “Chino Ántrax,” and one of the kingpin’s Colombian suppliers, Javier Calle Serna, are scheduled to be sentenced in California and Brooklyn later this year.

In June, Mykhaylo Koretskyy, a Ukrainian man known as “Russian Mike,” was extradited to Manhattan from Curaçao and may eventually stand trial in a case that will explore the drug lord’s business interests in Canada.

In another case in Manhattan, Fredy Renán Nájera Montoya, a former Honduran congressman, is being prosecuted on charges that he worked with the Sinaloa cartel to ship cocaine to Mexico from Honduras and murdered an army general and paid off the country’s former president.

Guzmán’s sentencing Wednesday will not be marked by much suspense: Because of the severity of his crimes, he faces a mandatory penalty of life in prison. It is probable that Guzmán will be sent to the U.S. Penitentiary Administrative Maximum Facility in Florence, Colorado, more commonly known as the ADX.

But there may be a fair share of drama Wednesday.

According the government, at least one of his many victims plans to address the court. (The identity of the victim has not yet been revealed.) Guzmán himself may also speak at the hearing in what could amount to the most expansive courtroom comments he has ever made.

This article originally appeared in The New York Times.