MEXICO CITY — He became a byword for government incompetence, a figure who seemed invincible after he burrowed his way out of the country’s most secure prison.
But on Friday, nearly six months after his escape, Joaquín Guzmán Loera, the Mexican drug lord known as El Chapo, was captured again after a fierce gun battle near the coast in his home state, Sinaloa, Mexican officials said. “Mission accomplished: We have him,” President Enrique Peña Nieto announced.
The arrest ended one of the most extensive manhunts undertaken by the government, involving every law enforcement agency in the country and help from the United States.
But it was the marines, Mexico’s most-trusted military force, who managed to capture the fugitive in an early morning raid that left five people dead, the Mexican authorities said. An American official also described the raid as “a Mexican op, planned and executed by Mexico.”
The government said late Friday that it had been watching a home in Los Mochis for more than a month when law enforcement officers finally saw movement on Thursday. Officials said that during the ensuing raid, Mr. Guzmán managed to slip away through the sewers, and then he surfaced, stole a car and was apprehended. The authorities took him to a hotel to wait for backup.
The capture of the drug lord concludes a deeply embarrassing chapter for the government of Mr. Peña Nieto, which has been waylaid by a series of security and corruption scandals that reached their low point with Mr. Guzmán’s daring escape.
Now, a looming question is whether the Mexican authorities will try to hold Mr. Guzmán for a third time — he has already escaped from prison twice — or whether they will hand him over to the Americans.
Mexican officials are busily debating the issue. Some are arguing for a “fast-track” extradition that could put him in the United States quickly, while others want to continue a previous process that could take months, according to two people with knowledge of the discussions. Mr. Guzmán, the head of Mexico’s most powerful cartel, is facing indictments in at least seven American federal courts on charges that include narcotics trafficking and murder.
Mr. Guzmán stunned the world last summer when he stepped into the shower in his cell, in the most secure wing of the prison, and abruptly vanished in full view of a video camera. Guards later discovered a small hole in the shower floor.
It led to a mile-long tunnel to a construction site. The tunnel was tall enough for Mr. Guzmán to walk through standing upright — his nickname translates to Shorty — and had been dug more than 30 feet underground. It was equipped with lighting, ventilation and a motorcycle on rails. Some engineers estimated that the tunnel took more than a year and at least $1 million to build.
The prison break humiliated the government of Mr. Peña Nieto, which had proclaimed the arrests of Mr. Guzmán and the leaders of other drug cartels as crucial achievements in restoring order and sovereignty to a country long beleaguered by the horrific violence associated with organized crime. It was particularly embarrassing because Mr. Guzmán had already escaped from prison in 2001, when his conspirators managed to smuggle him out. By some accounts, he escaped that time by hiding in a laundry bin.
There are still major questions ahead, including the potential extradition of Mr. Guzmán to the United States. Shortly after Mr. Guzmán was captured in 2014, the attorney general of Mexico at the time refused to extradite him to the United States, saying that the criminal would serve his time in Mexico first before he was sent to another country.
Officials and analysts said it was an effort to show sovereignty and put some distance between the Mexican authorities and their American counterparts, who often used a heavy hand to influence policy in Mexico.
A few months later, the Mexican government extradited several top drug lords to the United States, suggesting a new spirit of cooperation in the wake of Mr. Guzmán’s escape. The people extradited included an American citizen, Edgar Valdez Villarreal, a notorious figure known as “La Barbie,” as well as people charged with participating in the murders of a United States Consulate worker and an American immigration and customs agent.
While the likelihood that Mr. Guzmán could escape from an American maximum security prison is considered low, extradition would still come at a cost to the image of the Mexican state, some analysts say. “Extraditing him is a way to say we cannot cope with this with our own institutions,” said Pablo A. Piccato, a history professor at Columbia University. “While this is something everyone knows, obviously the government has not been able to publicly recognize this or tackle it in the past.”
Several senior politicians from Mr. Peña Nieto’s party were already calling for extradition, including Emilio Gamboa, the head of the governing party in the Senate, who told local news media that he agreed with the idea.
In a statement on Friday, the American attorney general, Loretta E. Lynch, commended the Mexican authorities “who have worked tirelessly in recent months to bring Guzmán to justice.” But she did not directly answer the extradition question
The Justice Department “is proud to maintain a close and effective relationship with our Mexican counterparts, and we look forward to continuing our work together to ensure the safety and security of all our people,” she said.
In the aftermath of Mr. Guzmán’s escape last July, American officials were frustrated with what they considered Mexico’s resistance to accepting help in the manhunt. After his escape, American officials offered to give their Mexican counterparts whatever assistance they could.
When Mexico rebuffed the offer, many officials in both countries worried that Mr. Guzmán might never be caught.
In October, security forces said they had located Mr. Guzmán in the remote northwestern mountains where he had been hiding out, an area known as the Golden Triangle at the border of his home state of Sinaloa, Durango and Chihuahua. After a gun battle, officials said, he escaped, with wounds to his face and leg.
The authorities ultimately captured Mr. Guzmán in Los Mochis, a coastal town of about 250,000 people that has long been known as a center of boxing in Mexico.
“People knew he would be caught any time; the government was going after him hard,” said Adrián Cabrera, a blogger in Culiacán, the capital of Sinaloa, adding that Mr. Guzmán was still a popular figure in Sinaloa.
“The new corridos will start coming out pretty soon,” Mr. Cabrera said, referring to the songs often used to glorify the exploits of local drug traffickers. “He’s from here. He has a lot of sympathy here. It’s his turf.”
When Mr. Guzmán was finally recaptured, the president broke the news himself, via Twitter. Given his sagging popularity — his ratings are the lowest of any president in the last 25 years — Mr. Peña Nieto seemed eager to declare the success personally.
In a statement on Friday, Mr. Peña Nieto said that the arrest was the culmination of months of work, an example of Mexico’s ability to overcome adversity. “Our security institutions have demonstrated that our citizens can trust them and that they have the stature, strength and determination to accomplish any mission they are tasked with,” Mr. Peña Nieto said.
Mr. Guzmán’s lawyers have already filed legal injunctions against his extradition to the United States. Wherever he ends up, few people here think that his capture will change much for the government’s popularity, life for Mexicans or the strength of the Sinaloa cartel. “This won’t have much effect on their internal structure,” said Eduardo Guerrero, a Mexico City-based security analyst. “They are prepared for this kind of news. They probably even have a protocol for it.”
New York Times