CALI, Colombia—This tropical city is known for the vibrant salsa music pulsating through its nightlife and the stately samán trees shading narrow streets. But a surge in cocaine trafficking has thrust Cali into the center of Colombia’s drug war.Soldiers patrol a street in Cali, where drug gangs battle for neighborhoods.In Cali’s mazelike, working-class barrios, community activist Wilson Muñoz said a turf war over local drug markets has left a young dealer in intensive care after being shot in the face. Elsewhere, Caleños, the term for locals, have found the dismembered human remains of murder victims dumped into local drainage canals.“The drugs are behind everything here,” Muñoz said.Cali has long been hard hit by violence, but a record supply of coca leaf, the agricultural ingredient of cocaine, is supercharging the flow of drugs and the intensity of violence. The resulting glut of cocaine hasn’t only flooded markets from the U.S. to Europe and Australia but has spilled onto the streets of Colombia’s third-largest city.Cocaine is now cheap enough for many Caleños to buy, saturating low-income areas. Local drug gangs are fighting deadly battles for neighborhoods, and security forces are increasingly facing violence as they try to clamp down on the strife.The security fallout is driving a tense national debate ahead of Sunday’s presidential election. Public anxiety over the growing power of armed gangs has fueled support for Abelardo de la Espriella, a populist conservative lawyer. He has surged in polls by promising an iron-fisted crackdown on drug-trafficking networks, including the construction of maximum-security prisons deep in the Amazon jungle.Cali poses a difficult challenge for the next president. There is no escaping its geography.To the south lies the province of Cauca, a volatile enclave home to some of the world’s most productive coca fields. Cauca yields crops with a remarkably high concentration of psychoactive alkaloid compounds—leaves chemically made into cocaine in remote labs.To the west, Pacific trafficking corridors carry multi-ton shipments toward the U.S. and European markets. Positioned near production and export, Cali acts as a natural urban funnel for the dirty money, contraband and violence generated by the cocaine trade.“There is not another city in Colombia that has at its feet a coca enclave of this magnitude,” said Juan Camilo Cock, executive director of the Alvaralice Foundation, a local crime-prevention nonprofit.In Cauca, the trade is dominated by heavily armed militias—part leftist insurgencies, part drug syndicates—frequently composed of renegade factions that broke away from the Revolutionary Armed Forces of Colombia, or FARC, after its 2016 peace accord with the government.The mountains around Cali have become a battleground, with counterinsurgency troops and police commandos striking cocaine labs and the gangs fighting back with everything they have.These rural syndicates don’t have a visible footprint inside Cali. Instead, police officials say they work with local street gangs to handle sales, run extortion rackets and carry out contract killings.“Outsourcing,” Gen. Herbert Benavidez, commander of Cali’s police force, calls it.Gang violence dictates the terms of daily life for many Caleños.“When they get into it, you have to close up everything,” said Yasmin Sánchez, 40 years old, who works at her family’s corner store. “They start shooting, and it doesn’t matter who gets hit.”The fight to dismantle these syndicates looks almost like a military effort.Shortly before dawn on a recent morning, more than 200 Cali police officers outfitted with battering rams, assault rifles and tactical shields raided a neighborhood. The target was the Monarchs gang, a crew that consolidated its hold on territory by—according to authorities—ruthlessly killing its opposition.Busting down doors, police arrested 23 suspected Monarchs without firing a shot.“If they’re off the streets, they’re not committing crimes,” Benavidez said.The vast wealth generated by the cocaine boom means the fight is never really over. Rural armed groups south of the city have upgraded their arsenals, deploying sophisticated, explosives-laden drones along with the latest assault rifles to attack government-security forces. Alejandro Eder, Cali’s mayor, said his forces have successfully intercepted drone attacks within city limits, but more attempts are expected.“They attack so that the military is distracted, so they can send the drugs over the mountains toward the Pacific,” Eder said.Cali’s struggle with narcotics syndicates is a multigenerational battle. In the 1990s, when the infamous Cali Cartel controlled 80% of U.S.-bound cocaine, the city’s homicide numbers topped 2,000 a year. Then-Mayor Rodrigo Guerrero, a Harvard-trained epidemiologist, began treating homicides as a public-health epidemic—mapping violence patterns to deploy police and social programs, a precursor to modern data-driven policing.By last year Cali’s homicides were down to 1,107, according to Colombia’s medical examiner. It is still among the highest murder rates in Latin America.City officials said law enforcement alone can’t match the financial allure of the drug trade for low-income youth. Eder’s approach balances increased security spending with targeted social programs.During Eder’s 2½-year-old administration, the city’s police force has expanded 14% and funding for surveillance cameras, vehicles and crime-prevention initiatives has jumped 30%. He is also spending more on infrastructure, schools and parks, leaning on public-private partnerships with Cali’s manufacturing, food-processing and corporate sectors.One such program, called On the Right Path, offers counseling, education and vocational training to former gang members and at-risk youth. At a workshop on the city’s western edge, financing from industrial firms like Fanalca—which operates a local Honda assembly plant—funds motorcycle-mechanics classes.Sergio Castañeda, a 22-year-old student at the workshop, said the program offered an exit ramp from the street gangs that prey on young people.“They’re told, ‘You have to kill someone to keep your spot,’ ” Castañeda said, describing the gangs’ entry requirements.Now, Castañeda is on track to graduate. His goal is to secure an entry-level position at the Honda plant.Similar business-backed coalitions are financing cultural-preservation programs, such as Carlos Molina’s Salsa Museum in the Workers Barrio. Supported by the civic development group ProPacifico, the museum provides musical instruments, job opportunities and neighborhood art tours to keep teenagers off the streets.“We give them music and culture,” Molina said. “So they have that opening and don’t get involved in negative things.”Write to Juan Forero at juan.forero@wsj.com