Updated

President Obama told U.S. troops in Afghanistan Sunday that America did not ask to be at war there, but he has ratched up the fight to make sure the Taliban and Al Qaeda can not experience a resurgence that would threaten U.S. national security.

In a surprise visit to the country, Obama included a visit to Bagram Airfield to thank the troops for their commitment in a terror fight that has now lasted eight and a half years and is witnessing an escalation of nearly 30,000 more U.S. troops to the country to face down increasingly engaged Taliban fighters.

"If this region slides backwards, if the Taliban retakes this country and Al Qaeda can operate with impunity, more American lives will be at stake," Obama told American forces, noting that the war was not something the United States went seeking. "Our broad mission is clear, we are going to disrupt and dismantle, defeat and destroy Al Qaeda."

The president said he would never send the troops to war unless they had a clear mission that included not only military offensives but a strengthening of Afghan security forces and government.

Obama also stressed U.S. public support for the troops even as he privately told the Afghan government of Hamid Karzai that it needs to shape up and reform its institutions.

"Thanks to you there has been progress these last several months," he told the troops. "We have seen a huge increase in support in stateside because people understand" the mission there and the success taking place by U.S. military and civilians.

"Your services are absolutely necessary, absolutely essential to America's safety and security. Those folks back home are relying on you," he said.

Behind closed doors Obama told President Karzai that he must deal with corruption and cut the flow of money from poppy production and drug trafficking that is sustaining the insurgency. The U.S. also wants Karzai to create an effective, credible judicial system and to halt cronyism and rewards for warlords in government hiring.

Both of Karzai's vice presidents are former warlords whose forces allegedly killed thousands of people in the civil war of the 1990s that paved the way for the rise of the Taliban.

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 -- the High Office of Oversight and Anti-Corruption -- including the authority to refer cases to court and act as prosecutor.

Obama has invited Karzai to the United States for a May 12 visit.

The president's one-day trip to Afghanistan -- shrouded in secrecy and darkness of night to ensure Obama's security -- was intended not just as a visit with Karzai, who learned on Thursday that the president was visiting, according to White House Press Secretary Robert Gibbs, but also to offer his support to troops as their commander in chief.

It was his second stop in a war zone since becoming president, coming about a year after a similarly secretive trip to Iraq and just two days after a threatening new audio message from Al Qaeda leader Usama bin Laden, who is believed to be hiding along the ungoverned border between Afghanistan and Pakistan.

Speaking in part for domestic consumption, particularly to his liberal base which opposes the war, the president repeated a comment of last December if he thought for a minute that America's vital interests were not at stake, he would order all the troops home right away. He added that politics may look messy on television, but Republicans and Democrats agree that support the troops is essential.

"There's no daylight when it comes to support of all of you. There's no daylight when it comes to supporting our troops," he said.

Indeed, a Washington Post poll out Sunday shows 53 percent approve of the president's handling of Afghanistan compared to 35 percent who disapprove. The poll, taken March 23-26 of 1,100 adults has shown a steady increase since Obama announced his Afghan strategy in November during a speech at West Point.

Obama added that everybody back home is grateful and understands the sacrifices troops and their families have made to keep America safe. He said in return he was fighting to improve military pay and benefits, increase child care and other family support systems, improve care for wounded warriors, expand education opportunities for GIs and increase the Veterans Affairs budget.

"At a time when too many institutions have put short-term gain in front of a commitment to what's right ... you've done your duty," he said, adding that the troops have earned their place next to the greatest of American generations.

With nearly 100,000 U.S. troops on the ground when the surge is complete, the number of U.S. casualties is rising. U.S. troops killed in Afghanistan has roughly doubled in the first three months of 2010 compared to the same period last year. At least 945 members of the U.S. military had died in Afghanistan, Pakistan and Uzbekistan as a result of the U.S. invasion of Afghanistan in late 2001, according to an Associated Press count.

The Associated Press contributed to this report.