Mayor Jorge Ramos' office said in a statement that putting army officers in charge will help "regain security" in Tijuana, where weekend attacks included nine beheadings and the death of four children caught in shootouts.
The city's police chief -- Public Safety Secretary Alberto Capella -- was replaced by his second-in-command, army Lt. Col. Julian Leyzaola. Another army officer, Capt. Gustavo Huerta, has been appointed the new No. 2.
Mexican President Felipe Calderon has relied heavily on the military in his fight against drug cartels and police in Tijuana are so mistrusted that the army once asked citizens to report crimes to soldiers. For a time last year, federal authorities took guns away from the police in this city across the border from San Diego.
Capella's appointment in December 2007 had been a surprise because he had no previous police experience. He had been a corporate lawyer and leader of a prominent anti-crime civic group, leading marches to demand improved security.
Capella told The Associated Press he respected the mayor's decision but was proud of his efforts to root out corruption within police ranks.
He acknowledged making "many enemies" during his time in office, noting that 100 police officers had been fired for suspected ties to drug cartels and another 62 resigned because of they "felt the pressure" of his anti-corruption drive.
Capella said he hoped his tenure showed that "humanity, honesty and courage" could drive public service in Tijuana.
The city government called Capella "an honest man" who "gave his best effort for Tijuana."
More than 200 people have been killed in the past month in Tijuana, where officials say rival cells of the Arellano-Felix drug cartel have been waging a bloody battle.
Capella's tenure in Tijuana was difficult before it even began. Just before he took office, 20 men dressed in black fired about 250 shots at his house one night. He ran alone from room to room with his rifle, firing from different windows until the assailants retreated.
The soft-spoken attorney kept a memento of the shootout in his windowless downtown office at police headquarters: a bullet-pocked copy of Hillary Clinton's "It Takes a Village." In an interview with the AP in June, Capella said he sent his family "far away" to keep them safe.
His dismissal followed a particularly bloody weekend in Tijuana. Among the nine men found decapitated Sunday were three police officers whose credentials were found stuffed in their mouths.
Police were investigating whether some of the 37 deaths between Saturday and Monday were part of a retaliatory spree sparked by the killing of a 25-year-old woman believed to be a drug trafficker's girlfriend, said Baja California state Attorney General Rommel Moreno.
He said interviews with families members indicated that 80 percent of the victims had been involved in drug dealing. But four of the dead were children.
Two brothers, aged 4 and 13, had been waiting for their parents outside a convenience store when gunmen opened fire, killing the boys and several adults. A 14-year-old boy working at locksmith's kiosk was shot dead in an attack on a neighboring business. And a 12-year-old was killed when the car he was riding was sprayed with bullets.
Violence has soared in Mexico as drug cartels compete for smuggling routes and battle government forces.
Mexican newspapers have reported that more than 4,000 people have been killed across the country this year in drug-related violence. The federal government does not regularly release homicide figures.