KABUL - Insurgents killed three U.S. soldiers in Afghanistan on Thursday in a bomb and small-arms attack on their vehicle, the military said.

The attack came hours before President Barack Obama made a speech to the Muslim world in which he said he did not want to keep troops in Afghanistan, but they were currently needed to fight extremists intent on killing as many Americans as they can.

"It is agonizing for America to lose our young men and women," said Obama, who has ordered 21,000 extra troops to Afghanistan to battle an increasingly widespread and effective Taliban insurgency eight years after the U.S.-led invasion.

Humayun Hamidzada, a spokesman for President Hamid Karzai, said Obama's statement in Egypt "reflected the reality."

"We are grateful for the support and sacrifice of the U.S. but we would like to stand on our own two feet as quickly as possible," he said.

Thursday's attack took place in Kapisa, a province just north of the capital of Kabul and the location of Bagram, the main U.S. base in Afghanistan, the U.S. military said in a statement. Another soldier was injured, but the nationality was not released.

Kapisa is considered a stronghold of insurgents loyal to Afghan warlord Gulbuddin Hekmatyar.

It was the third attack in less than a week near the Bagram base.

On Tuesday, a family of six Afghans was killed in a suicide attack in Parwan district, while on Saturday three U.S. soldiers died in a suicide attack in Kapisa.