His bid to shore up faith in the struggle was aimed both at the troops who cheered him and Americans back home. And, he demanded accountability from Afghan authorities to make good on repeated promises to improve living conditions, rein in corruption and enforce the rule of law to prevent people from joining the insurgency.
"Your services are absolutely necessary, absolutely essential to America's safety and security," the president told a lively crowd of about 2,500 troops and civilians at Bagram Air Field north of Kabul. "Those folks back home are relying on you. We can't forget why we're here."
It was Obama's first trip as president to Afghanistan, where the number of U.S. troops killed has roughly doubled in the first three months of 2010 compared with the same period last year as Washington has added tens of thousands of additional soldiers to reverse the Taliban's momentum.
"We did not choose this war," Obama reminded the troops, recalling the Sept. 11, 2001, attacks and warning that al-Qaida was still using the region to plan terrorist strikes against the U.S. and its allies. "We are going to disrupt and dismantle, defeat and destroy al-Qaida and its extremist allies."
Obama had gone Friday afternoon to the presidential retreat at Camp David, Md., from which unnoticed departures are easier because of its secluded mountain location. The small contingent of White House aides and media brought on the trip were sworn to secrecy. Obama arrived in Kabul just two days after a threatening new audio message from al-Qaida leader Osama bin Laden, believed to be hiding along the ungoverned border between Afghanistan and Pakistan.
"I thought I'd come over and say hello," Obama told the troops in a jaunty remark that set the stage for stark reminders of the terrorist threat that rose from this soil.
"If this region slides backwards," he said, "if the Taliban retakes this country, al-Qaida can operate with impunity, then more American lives will be at stake, the Afghan people will lose their opportunity for progress and prosperity and the world will be significantly less secure. As long as I'm your commander in chief, I'm not going to let that happen."
That resolve was meant just as surely for stateside citizens as for the people who heard it face to face. Polls find that Americans are divided on the war if, more recently, favorable to Obama's handling of it.
Obama's dark suit was soiled with dust when he stepped off his helicopter at the presidential palace in Kabul. White House officials said Obama, in private talks, wanted to drive home the point that Afghan President Hamid Karzai and his Cabinet must do more to battle corruption and cronyism in government.
Karzai "needs to be seized with how important that is," said Jim Jones, Obama's national security adviser. Karzai has raised eyebrows in Washington with recent trips to Iran, China and Pakistan and his welcoming Iranian President Mahmoud Ahmadinejad to Kabul this month.
In public remarks,Obama told Karzai and his cabinet that he was pleased with progress made since their last discussion by secure videoconference on March 15. Obama invited him to visit Washington on May 12. He also praised recent steps in the military campaign against insurgents. But he stressed that Afghans need to see conditions on the ground get better.
"Progress will continue to be made ... but we also want to continue make progress on the civilian front," Obama said, referring to anti-corruption efforts, good governance and adherence to the rule of law. "All of these things end up resulting in an Afghanistan that is more prosperous and more secure."
Karzai promised that his country "would move forward into the future" to eventually take over its own security, and he thanked Obama for the American intervention in his country.
He told Obama he has begun to establish more credible national institutions on corruption and made clear he intends to make ministerial appointments more representative of the multiple ethnic and geographic regions of the country, according to a U.S. account of the meeting.
The White House insisted that Karzai's Cabinet participate in most of the meetings with Obama. The Cabinet includes a number of ministers favored by the U.S., including the heads of finance, interior and defense, whom the Obama administration wants to empower as a way of reducing the influence of presidential cronies. Some talented Afghan administrators have complained that Karzai marginalized them in an attempt to solidify his powers.
"We have to have the strategic rapport with President Karzai and his Cabinet to understand how we are going to succeed his year in reversing the momentum the Taliban and the opposition forces have been able to establish since 2006."
The Afghan government has tried to tackle corruption in the past with little success but Karzai pledged after fraud-marred August elections to rein in graft by making officials declare their assets and giving the country's anti-corruption watchdog more power to go after those accused of misusing their office. This month he gave more powers to an anti-corruption body, including the authority to refer cases to court and act as prosecutor.
Initially, the White House said Karzai had been informed of Obama's impending visit just an hour before his arrival. But Obama's press secretary, Robert Gibbs, said later that the Afghan government was told about the trip on Thursday.
At least 945 members of the U.S. military have died in Afghanistan, Pakistan and Uzbekistan since the U.S. campaign started in late 2001, according to an Associated Press count.
Obama, speaking to troops in a cavernous tent known as the "clam shell," said, "We know there's going to be some difficult days ahead, there's going to be setbacks. We face a determined enemy, but we also know this: the United States of America does not quit once it starts on something. We will prevail, I am absolutely confident of that."
In December, Obama ordered 30,000 additional forces into the fight against the Taliban. Those new U.S. troops are still arriving and most are expected to be in place by summer, for a full force of roughly 100,000 U.S. troops. There were about 34,000 when Obama took office.