The shootout took place on Sunday on a road in the town of Valle Hermoso, some 40 kilometers (25 miles) from the US border, in the state of Tamaulipas.
The soldiers were on the road when they saw armed civilians and ordered them to stop, according to the Tamaulipas Coordination Group of federal and state security forces.
The civilians "ignored them and began to shoot at the soldiers, who repelled the attack in self-defense," the group said in a statement.
The Gulf cartel and their rivals, Los Zetas, have fought brutal turf wars in Tamaulipas for years.
On Saturday, 11 members of the same family were killed by gunmen in their home in Ciudad Victoria, the state capital.
Three people from another family were murdered less than an hour later in another home.
The government said the killings in Ciudad Victoria appeared to be related to a dispute between rival gangs.
