MAZATLÁN, Mexico — They reacted here with utter disbelief. Joaquín Guzmán Loera, El Chapo, drug kingpin to the world, the Robin Hood of Sinaloa, had been arrested in his home state, in the resort town that is a loyal fief of his empire?

“It was too easy,” said a young woman of model height, her back to the sea, her eyes fixed on the 12-story condominium where Mexican marines and United States agents grabbed him early on Saturday morning. “No shootout, no final stand?”

The takedown this weekend of the world’s most wanted man — the chief executive of what experts describe as the world’s most sophisticated narcotics enterprise, the Sinaloa cartel — upended long-held assumptions about the impunity of Mexican mobsters.

It also overturned long-lowered expectations of what was possible in the game of cat and mouse, or government versus outlaws, that has defined the drug war here.

Mr. Guzmán, after all, seemed untouchable, relying time and again on intimidation, bribery and local accommodation — even pride — to help him keep his freedom and his power.

But the giant known as Shorty fell with an odd humility, awakened shirtless by the authorities before 7 a.m. on Saturday. He neither died in a blaze of glory nor managed another daring escape; persistence carried him away.

The details of the operation, recounted by American and Mexican officials and witnesses here (most requested anonymity for their own protection) show that Mr. Guzmán’s arrest, after countless near misses and narrow escapes, came down to a tight bond between the Drug Enforcement Administration and the Mexican navy, some well-kept secrets, and a fair amount of luck.

Even as security cooperation between Mexico and the United States continued to be hampered by distrust at the highest levels of government, American agents and Mexican marines worked together for weeks, until the moment of capture here when they crashed through the door of a fourth-floor apartment overlooking the Pacific.

It began with a meeting a few weeks ago. The D.E.A. presented a body of intelligence information to Mexican navy officials, including calls and contacts from cellphones used over the last few months. The Americans had worked closely before with the marines on successful operations but were not certain that their counterparts would take on the mission. Mexican security forces were focused on another problem — the battle between the Knights Templar cartel and self-defense groups in Michoacán — and President Enrique Peña Nieto had made clear that the economy was his priority. Officials said there were local obstacles, too. Many Sinaloans considered Mr. Guzmán as a kind of favorite rebel son. His cartel has deep roots across the state, with many arguing that his operation is relatively benign in comparison to some newer groups that rely more on extortion and kidnapping.

“It’s an old model of organized crime that’s not predatory on the local population,” said Alejandro Hope, a security analyst and former Mexican intelligence officer whose mother grew up in Sinaloa. Still, he added, “For all the talk of Chapo as a good narco, this is the person who was responsible for some of the worst violence — for the drug war in Tijuana and Juárez. That’s thousands of deaths.”

Mr. Guzmán, though, seemed so immune to consequence that some here in Mazatlán had even come to believe he might be protected, or at least tolerated, by elements of the Mexican and American governments. “We thought he was clean,” one businessman said.

But the marines, compelled by the intelligence gathered through wiretaps and informants — especially tips suggesting that Mr. Guzmán was showing up again in Culiacán and Mazatlán — agreed to move. They “surged up,” one American official said, at a base near Cabo, the southern tip of the Baja Peninsula, a short race across the water to Mazatlán and the rest of Sinaloa.

Starting roughly a month before Mr. Guzmán’s capture, they began to sweep methodically through Culiacán, the Sinaloa state capital. They knocked down doors and recovered weapons, armored cars, drugs, cash.

The drug operators scurried. On Feb. 13, three men were arrested on the road to Mazatlán, including a man called “19,” believed to be the new head assassin for one of Mr. Guzmán’s senior officers, Ismael (Mayo) Zambada. On Feb. 17, another senior leader was captured with 4,000 hollowed-out cucumbers and bananas filled with cocaine.

A half-dozen others followed and with each arrest and seizure, Mexican officials made sure to emphasize that they were seeking Mr. Zambada. The true nature of the operation never leaked — in part because of Mr. Guzmán’s legend. No one seemed to suspect that he would come down from his secret hiding spots in the mountains of Sinaloa, or further afield, in Guatemala or wherever else.

And how much would it matter if he did? Experts suspected he had delegated much of the day-to-day work, and drugs have been moving north from this fertile region since World War II, when the American government needed opium for its wounded soldiers. With demand for heroin surging yet again, no one doubts that the trade — “the life,” as some here call it — will go on.

But with momentum building in Culiacán, American officials said that the Mexican marines began to believe they might actually get the target that had slipped their grasp so many times before.

A small team of American agents with the D.E.A. and the United States Marshals Service were embedded with the Mexican marines, American and Mexican officials said, and in their ranks, too, confidence was rising, and mixing with impatience. As days dragged to weeks, there was a sense that Mexican officials wanted to wrap things up — especially after a raid led to what appeared to be a near miss.

Working on information from some of Mr. Guzmán’s bodyguards, Mexican marines and American agents raided the home of his ex-wife on Thursday. After struggling to batter down the steel-reinforced door, according to the Mexican authorities, they were too late: instead of finding their prey, they discovered a secret door beneath a bathtub that led to a network of tunnels and sewer canals that connected to six other houses.

The search continued, but the earlier arrests and intelligence were pointing south, to Mazatlán — one of Mexico’s first resorts.

Mr. Guzmán was not known to spend much time here; local businessmen with a lifetime of knowledge about Sinaloa’s connections to the community said there were no known Chapo sightings, or serious rumors, over his many years in power.

The building he chose, called the Miramar, was built about a decade ago, they said, and was filled with a mix of vacationers — Mexicans and American and Canadian retirees — who came and went through the year. Before dawn on Saturday morning, it seemed to be just another place to enjoy the view. But about 12 hours earlier, an intercepted phone call to Mr. Guzmán’s cellphone had already triggered the command to move. In the dark of night, neighbors heard knocks on the doors, according to interviews via apartment intercom. American officials said the teams did not know which apartment he was in. Then came a crash.

By the time retirees down the block heard helicopters — “I was waiting to hear the gunfire,” one Canadian woman said — it was over.

Mr. Guzmán was arrested with one other man, Mexican officials said. Some reports said that the authorities also found a woman in the apartment and photos of the room show two pink children’s suitcases on a bed, suggesting Mr. Guzmán was with his wife and twin 2-year-old daughters who were born in Los Angeles County. But American officials said they were surprised by what was not there: a cache of weapons. Not a single shot was fired.

Local residents cast doubt on the operation for that exact reason. “Everyone thinks it was a negotiated capture,” said one local business leader.

That it happened just a few days after President Obama visited Mexico, during a week when official figures showed the economy grew by only 1.1 percent, has only added to the skepticism. Even after photos and forensic tests, many here, young and old, don’t believe that the man with the mustache trotted out for the cameras on Saturday — and now confined to a high-security Mexican prison, officials said — is really the one they call Chapo.

“It’s a fantasy,” said Ofelia Aguilar, 52, walking through a shantytown called Santa Monica, still filling up with families who have been forced to flee the lawlessness of the Sinaloan countryside where Mr. Guzmán grew up. “It has to be someone else. I just don’t believe it.”

Randal C. Archibold contributed reporting from Mexico City and Ginger Thompson from New York.

A version of this article appears in print on , on Page A1 of the New York edition with the headline: How a Kingpin Above the Law Fell, Incredibly, Without a Shot. Order Reprints | Today’s Paper | Subscribe