US President Barack Obama has said there will be no quick or easy victory over the Taliban.
But he told a meeting of veterans in Arizona the conflict in Afghanistan was a "war of necessity", crucial in protecting Americans from terrorism.
"If left unchecked, the Taliban insurgency will mean an even larger safe haven from which al-Qaeda would plot to kill more Americans," he said.
He spoke as campaigning for Thursday's elections in Afghanistan ended.
Earlier, a survey by the BBC's Afghan service suggested that the government has limited or no control in 30% of the country.
A spokesman for President Hamid Karzai said the government did not agree with the findings, and that there were security problems in just a few districts.
President Obama is winding down America's unpopular war in Iraq and stepping up the campaign in Afghanistan.
The insurgency in Afghanistan didn't just happen overnight and we won't defeat it overnight
US President Barack Obama
As he does so, he is working hard to shore up support for the fight against the Taliban.
He is sending 30,000 extra troops to Afghanistan and success or failure there will help determine how history views his administration.
Mr Obama says this is a war of necessity, not choice, but the US lost 44 soldiers in Afghanistan in July and at least one opinion poll has shown a drop in popular support for the mission.
Speaking to an audience of military veterans in Phoenix, Mr Obama appeared to be preparing US opinion for the long haul.
Washington is planning to send an extra 30,000 troops to Afghanistan
"The insurgency in Afghanistan didn't just happen overnight and we won't defeat it overnight," he said.
"This will not be quick, nor easy. But we must never forget this is not a war of choice, this is a war of necessity."
This week's Afghan presidential and provincial elections will provide a test of the new US strategy of providing security on the ground, while also working to engage Pakistan in some kind of move towards regional stabilisation.
Significantly, Mr Obama did not discuss the likely outcome of those elections.
US enthusiasm for Mr Karzai has dwindled over the years and the prospect of him winning a second term is viewed in Washington with resignation rather than hope.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.