The French troops had been caught up in fighting that started on Monday in the area of Sirobi some 50 km (30 miles) east of Kabul.
They were killed "during a joint reconnaissance mission with the Afghan National Army", Mr Sarkozy said in a statement.
"Serious measures, notably in the air, were taken to support and extricate our men caught in an extremely violent ambush."
The French leader said his visit to Afghanistan would be to show his support for French troops there.
France has 3,000 troops deployed in Afghanistan. Tuesday's deaths bring to 24 the number killed since 2002, AFP says.
"The French were ambushed in a village after they left the Ozbin valley," an Afghan intelligence officer told the BBC.
"They were ambushed from several directions. The Taleban and al-Qaeda forces used heavy machine guns and other weapons. They fired from mountains and gardens."
The fighting went on for 24 hours.
The French recently took over control of the Kabul regional command which includes Sirobi.