President Barack Obama said on Wednesday a "time of war" was ending in a moment of US renewal, after slipping into Afghanistan on the anniversary of Osama bin Laden's death.
In a highly political election-year address from outside Kabul, Obama posed as a commander-in-chief who ended two long wars and crushed Al-Qaeda, and tried to conjure up a new dawn for a nation exhausted by conflict and recession.
"This time of war began in Afghanistan, and this is where it will end," Obama said, recalling a decade-long "dark cloud of war", as America fell into an Afghan morass after bin Laden plotted the September 11 attacks in 2001.
"Yet here, in the pre-dawn darkness of Afghanistan, we can see the light of a new day on the horizon," said Obama, seeking to use political capital earned by bringing troops home to validate his request for a second White House term.
Obama earlier dropped from the night skies into Kabul in secrecy and signed a deal with President Hamid Karzai, cementing 10 years of US aid for Afghanistan after NATO combat troops leave in 2014.
"Neither Americans nor the Afghan people asked for this war, yet for a decade we've stood together," Obama said at the signing ceremony at Karzai's presidential palace.
"We look forward to a future of peace. We're agreeing to be long-term partners," said the president, who later headed home aboard Air Force One after just six hours on the ground.
About two hours after his departure, Afghan police said a suicide car bomb detonated in an area of Kabul close to several foreign military bases, prompting the US embassy to warn staff to take cover and go into lockdown.
The explosion was a reminder of the extremist threat that stalks Afghanistan still, with the Taliban resurgent a decade after they were driven from power for refusing to hand over bin Laden following the 9/11 attacks.
Karzai said the US pact "is not only not threatening any third country, including the neighbouring countries, but we are hoping that this leads to stability, prosperity and development in the region".
Neighbouring Pakistan has a key role to play in Afghanistan's future, but its relationship with both Kabul and Washington remains mired in mistrust a year after bin Laden was found and killed by US commandos on its soil.
The US-Afghan pact, agreed last month, sees the possibility of American forces staying behind to train Afghan forces and pursue the remnants of Al-Qaeda for 10 years after 2014.
It does not commit Washington to specific troop or funding levels for Afghanistan, though is meant to signal to US foes that despite ending the longest war in US history, Washington intends to ensure Afghanistan does not revert to a haven for terror groups like Al-Qaeda.
But after a war that has cost the lives of nearly 3,000 US and allied troops, maimed tens of thousands more, saw thousands of Afghans killed and cost hundreds of billions of dollars, Afghanistan's future is deeply uncertain.
Obama trod a delicate political line, reassuring Americans the war was ending but steeling them for possible sacrifices to come -- all while trying to pivot politically back to the need to rebuild at home.
Furious Republicans have accused him of exploiting the heroism of Navy SEAL special forces who conducted the raid to kill bin Laden in the Pakistani garrison town of Abbottabad on May 2 last year.
But the president, who faces a tough re-election fight, did not shirk from presenting himself as the man to shepherd his country out of "a decade of conflict abroad and economic crisis at home".
"It is time to renew America," Obama said at Bagram air base, against a backdrop of military vehicles in their sandy desert liveries.
"A united America of grit and resilience, where sunlight glistens off soaring new towers in downtown Manhattan, and we build our future as one people, as one nation."
Though he sought to put a capstone on the war, Obama's statement effectively meant that US troops could be fighting for two more years, and some could remain in danger for a decade after that.
Obama bluntly told US soldiers that "some of your buddies are going to get injured, some of your buddies may get killed".
"There is going to be heartbreak and pain and difficulty ahead, but there is a light on the horizon because of the sacrifices you have made."
A Pentagon report issued Tuesday laid out the challenges, saying security had improved in most of Afghanistan but that insurgent sanctuaries in Pakistan and pervasive corruption pose "long-term and acute challenges".
About 87,000 US troops and 44,000 other international forces are deployed in Afghanistan along with 344,000 Afghan army and police, the report said.
A senior US official said the post-war partnership deal signed after months of wrangling with Karzai would make "clear to the Taliban, Al-Qaeda and other international terrorist groups that they cannot wait us out".
The deal states that the United States does not seek permanent military bases in Afghanistan and was concluded just over two weeks before a NATO summit in Chicago.
On Monday, Obama had publicly questioned whether his Republican opponent Mitt Romney would have taken the same decision as he did to launch the audacious raid that killed bin Laden deep in Pakistan.
Romney accused Obama of inappropriately exploiting a moment of great national unity for political gain.
"Of course, I would have taken out Osama bin Laden, but what's the right course for the economy?" Romney said on CBS programme "This Morning".