The ministry said in a statement that the operation to rescue the kidnapped soldiers had taken place in the southern Apure State, on the border with Colombia, on Monday.
Medical support was being given to the soldiers and they were all “safe and sound,” the Defense Ministry said.
It added that the Venezuelan military continued a search for two other troops that remained missing, but did not give further details.
“We will continue to fight against organizations that want to use our sacred national territory to commit transnational crimes affecting the peace, development and stability of the country,” the statement said.
The soldiers had been kidnapped by the armed groups active in the border area on May 15.
The Venezuelan military launched on a large-scale operation to combat the militia on the Colombian border earlier this year.
Caracas has said the armed groups are disguised as guerrillas but are in fact tied to the Colombian army and the government of Colombian President Ivan Duque.
But security sources in Colombia claim that the armed groups are dissidents from the now-disbanded Revolutionary Armed Forces of Colombia (FARC) rebel group, which signed a peace agreement with Bogota in 2016 to end a half-century of armed conflict. Some guerrilla fighters refused to join the peace process.
Early this year, Human Rights Watch (HRW) warned in a report that residents in Apure and the neighboring Colombian state of Arauca faced brutal violence from armed militants on a daily basis.