A military aircraft flying over Ciudad Mier in Tamaulipas state spotted several gunmen in front of a building, according to a statement from Mexico's Defense Department.
When ground troops moved in, gunmen opened fire, starting a gunbattle in which 25 suspected cartel members died, according to the military. The statement said two soldiers were wounded.
Authorities rescued three people believed to be kidnap victims in the raid, according to the statement. The military said troops seized 25 rifles, four grenades, 4,200 rounds of ammunition and 23 vehicles.
Earlier, a military spokesman said the gunmen were believed to be on a property controlled by the Zetas, who started out as a gang of drug assassins but have since evolved into a powerful cartel.
Some local media reported 27 suspected cartel members were slain, citing unnamed police officials.
Violence has surged in northeastern Mexico this year since the Zetas broke ranks with their former employer, the Gulf cartel, resulting in a flare-up of drug violence in Tamaulipas.
Last week, marines discovered the bodies of 72 Central and South American migrants believed to have been gunned down by the Zetas after refusing to work for the cartel, in what may be the deadliest drug gang massacres to date. The migrants' bodies were discovered at a ranch about 100 miles (160 kilometers) from the U.S. border in Tamaulipas.
Five days later, the mayor of the Tamaulipas town of Hidalgo, bordering Nuevo Leon state, was ambushed and killed in his car in an attack that also wounded his daughter.
In June, gunmen ambushed and killed the leading candidate for state governor a week before regional elections. And in May a mayoral candidate in Tamaulipas was assassinated.
Drug violence has claimed more than 28,000 lives since President Felipe Calderon intensified a crackdown on cartels after taking office in late 2006.