The troops were on patrol in the town of San Jose de Lourdes in northern Zacatecas state when they came under fire from gunmen inside a safehouse, Mexico's navy said in a statement. It said 17 gunmen were detained.
The Zetas drug cartel began expanding into Zacatecas from the border state of Tamaulipas two years ago after it split from the Gulf cartel.
Clashes between troops and cartel gunmen have become common in Mexico's drug war, which has claimed more than 35,000 lives since President Felipe Calderon deployed thousands of federal troops and police to fight traffickers four years ago. The offensive led to a splintering of the country's cartels and increased fighting among gangs over territory.
Elsewhere in the north Friday, a spray-painted sign threatening death for U.S. Drug Enforcement Administration agents was found next to a school in the northern city of Chihuahua, officials said.
Addressed with profanity to "Gringos (D.E.A.)," the unsigned graffiti warned: "We know where you are and we know who you are and where you go. We are going to chop off your (expletive) heads."
Anonymous messages conveying threats and other warnings are common in areas hit hard by Mexico's drug war, but it is rarer for them to threaten U.S. law enforcement. Authorities do not know who left the message, which was removed.
The DEA referred questions to the U.S. State Department. Officials there did not immediately respond to requests for comment.
The message was left in the Chihuahua state capital, also called Chihuahua, which is about 220 miles (360 kilometers) from the U.S. border.
In February, suspected Zetas killed U.S. Immigration and Customs Enforcement agent Jaime Zapata and wounded colleague Victor Avila on a highway in San Luis Potosi state.
Five copies of a message addressed to Chihuahua Gov. Cesar Duarte were also found Friday painted on blankets known as "mantas" in Ciudad Juarez, a city across the border from El Paso, Texas. Those messages, apparently posted by rivals of the Sinaloa drug cartel, accused officials of protecting the Sinaloa organization.
It was not clear if the messages in Chihuahua and Ciudad Juarez were related.
"This sort of message will not stop us from continuing the fight to bring peace back to this state," Chihuahua Interior Secretary Graciela Ortiz said.
The threatening message against Duarte comes amid threats to the governor of Nuevo Leon, another northern state bordering Texas. Two of Gov. Rodrigo Medina's bodyguards were mutilated, killed and dismembered in June.
Also in Nuevo Leon, gunmen tried to assassinate the mayor of Santa Catarina, a town where the police chief was slain Monday, officials said.
Mayor Gabriel Navarro escaped injury when his eight bodyguards drove off the attackers, state public safety spokesman Jorge Domene said.
On Monday, authorities say, Santa Cararina Police Chief German Perez's bodyguards and other police officers did nothing to stop gunmen who burst into his office and shot him to death. Seven city police officers are under investigation.
Navarro had said hours before Friday's attack that he fired city Public Safety Secretary Manuel Uco and the director of traffic police, Antonio Marroquin. Uro has been questioned in Perez's killing, but authorities haven't said if he is considered a suspect.