Heavy fighting broke in northern Mexico after the security forces seized one of the sons of jailed drug kingpin Joaquín "El Chapo" Guzmán. However Mr Guzmán was later released - to avoid further violence, the authorities said.
Ovidio Guzmán, said to be in his 20s, is believed to have played a key role in the Sinaloa cartel, following the arrest of his father. He is wanted in the US on several drug-related charges, Mexican media report.
Mexico’s security minister, Alfonso Durazo, said a patrol by National Guard militarised police first came under attack from within a house in the city, 600 km (370 miles) northwest of Mexico City. After entering the house, they arrested Ovidio Guzmán López, who is accused of drug trafficking in the United States.
However, the patrol was quickly overpowered by cartel gunmen, and the decision was taken to withdraw to protect the lives of the National Guard and restore calm in the city, where gangsters had set up roadblocks and were unleashing heavy automatic gunfire, Durazo said.
Images shared on social media showed trucks with mounted heavy machine guns patrolling the city streets. Another clip showed a gunman with an assault rifle shooting at an unknown target against a soundtrack of continuous gunfire.
Mr Guzmán was arrested but later released, "to avoid more violence in the area and preserve the lives of our personnel and recover calm in the city", Mr Durazo said.
Mr Obrador was elected on a platform of cracking down on Mexico's drug cartels, and has tasked a new security force, the National Guard, with fighting them. Under El Chapo's leadership, the Sinaloa cartel was the biggest supplier of drugs to the US, officials say.
With El Chapo now behind bars, the cartel is said to be partially controlled by Ovidio Guzmán, who is accused of drug trafficking in the US.
The state government said Ovidio Guzmán was found in a house by a police patrol on a routine search. It said cartel members subsequently launched the huge attack in an attempt to seize him back from the authorities.