Sarkozy spoke to French troops from units who lost some of the 10 soldiers killed in a fierce Taliban ambush and firefight in mountains about 30 miles east of Kabul on Monday. Sarkozy was greeted by a color guard and the playing of the French national anthem at the Kabul NATO base.
The French president also visited some of the 21 soldiers wounded in the battle. He told a group of soldiers some 200 strong that France must learn lessons from the attack and change its procedures.
"Even though the toll is so high, you should be proud of what you are doing. The work that you're doing here is indispensable," Sarkozy told the troops. "We're gong to make sure that the means are put in place to ensure that this doesn't happen again."
Sarkozy also met with Afghan President Hamid Karzai at the presidential palace. Karzai said he wanted to "express the condolences and the pain of the Afghan people to the French people for the loss that they have suffered."
Karzai attributed the recent rise in violence in his country to the lack of attention that NATO and Afghanistan has paid to militant sanctuaries and training grounds, a clear reference to Pakistan's tribal area.
"Unless we do that (pay more attention) we will continue to suffer," Karzai said.
The French soldiers were on a reconnaissance mission when they were ambushed by a force of about 100 militants in the mountains of Surobi. France's top military official, Gen. Jean-Louis Georgelin, said most of the French casualties came in the minutes after the soldiers ascended a mountain pass.
French Defense Minister Herve Morin said about 30 militants were killed and 30 wounded. Taliban fighters and militants allied to renegade warlord Gulbuddin Hekmatyar operate in Surobi.
It was the deadliest attack on international troops in Afghanistan since June 2005, when 16 American soldiers were killed when their helicopter was shot down by a rocket-propelled grenade.
The French president boarded a plane for Afghanistan shortly after the news was announced, breaking away from his vacation in the south of France.
Sarkozy on Tuesday said his commitment to the 40-nation Afghan mission "remains intact."
Militants are showing greater determination to confront U.S. and NATO troops in their attempt to wrest back the control they lost nearly seven years ago.
In the latest violence, some 19 Taliban fighters were killed in two separate clashes in the eastern provinces of Khost and Paktia.
Ten militants were killed in Alisher district of Khost province early Wednesday after they attacked a construction company, said provincial police chief Esmatullah Alizai. He said Afghan police and coalition troops responded, killing the militants.
The Khost governor, Arsallah Jamal, said one construction worker was wounded in the attack.
Another nine militants were killed in clashes in Zormat district of Paktia province on Wednesday, said Abdul Qayum Bakizoy, the provincial police chief. The militants had gathered in an open area when Afghan and foreign troops attacked them, Bakizoy said. There were no casualties among Afghan and foreign troops.
More than 3,400 people - mostly militants - have been killed in insurgency-related violence this year, according to an Associated Press count based on figures from Western and Afghan officials.