(updates with quotes from Obama)
By Steve Holland
BAGRAM AIR BASE, Afghanistan, May 25 (Reuters) - President Barack Obama made a surprise trip to Afghanistan on Sunday to visit U.S. forces who are wrapping up a 13-year mission and signaled that he intends to keep a small number of troops in the country for training and counter-terrorism operations.
Cheers erupted among the hundreds of U.S. troops gathered in a Bagram hangar when Obama said that at the end of this year, "America's war in Afghanistan will come to a responsible end."
With Afghanistan immersed in a runoff election to choose a successor to President Hamid Karzai, Obama did not meet Afghan government officials nor travel to the capital Kabul. Karzai has long been out of favor with Washington over his refusal to sign a bilateral security agreement to allow U.S. troops to stay beyond 2014.
Obama's fourth visit to Afghanistan came as he faces criticism at home over a foreign policy often derided as too passive in dealing with crises from Syria to Ukraine and Russia. He is to respond to those criticisms in a speech on Wednesday at the U.S. Military Academy at West Point.
Karzai's refusal to sign the bilateral security agreement has exacerbated concerns about the country's prospects for stability as the Taliban insurgency rages on, and has contributed to a steep economic downturn in recent months.
Obama administration officials briefed on the matter told Reuters last month that the number of U.S. troops in Afghanistan may drop well below 10,000 beyond 2014, the minimum demanded by the U.S. military to train Afghan forces.
The decision to consider a small force, possibly less than 5,000 U.S. troops, reflects a belief among White House officials that Afghan security forces have evolved into a robust enough force to contain a still-potent Taliban-led insurgency, the officials said.
There are now about 33,000 U.S. troops in Afghanistan, down from 100,000 in 2011, when troop numbers peaked a decade into a conflict originally intended to deny al Qaeda sanctuary in Afghanistan after the Sept. 11, 2001, attacks.
The two leading candidates in Afghanistan's presidential race, Abdullah Abdullah and Ashraf Ghani, have both pledged to sign the security agreement as soon as possible, should they be elected in the second round of voting scheduled for June 14.
The new president may not start work until August, as logistical constraints and widespread fraud could mean it will take the country's electoral commission weeks to determine the outcome of the vote.
Obama called Karzai from his plane after leaving Bagram, saying he wanted to conclude a bilateral security agreement with the next president. He also told Karzai he would inform him of his decision on post-2014 troop levels before making it public, a senior administration official told reporters on the plane.
COUNTRY MUSIC AND PATRIOTISM
At Bagram, Obama addressed the troops just after a performance from country music star Brad Paisley, who joined him for the Air Force One ride halfway around the world, a trip kept under wraps until the plane arrived.
"Once Afghanistan has sworn in its new president, I'm hopeful we'll sign a bilateral security agreement that lets us move forward," Obama told the troops.
"We want to preserve the gains that you have helped to win. And we're going to make sure that Afghanistan can never again, ever, be used again to launch an attack against our country."
Obama's remarks were laced with patriotic praise for troops ahead of the U.S. Memorial Day on Monday, a holiday of remembrance for those Americans who lost their lives in wars.
"I know sometimes when you're over here, away from home, away from family, you may not truly absorb how much the folks back home are thinking about you. So I just want you to know, when it comes to supporting you and your families, the American people stand united," he said.
Criticized at home for his handling of a controversy involving healthcare delays for veterans, Obama vowed his administration will uphold the "sacred obligation" to take care of those who had served in the U.S. military.
Obama got a briefing from the Army general who commands U.S. and NATO forces here, Joe Dunford, and U.S. Ambassador to Afghanistan James Cunningham. He said he would announce "fairly soon" how many troops the United States would like to leave behind.
Obama's visit to Bagram took place late on Sunday night local time. He was joined by national security adviser Susan Rice and senior adviser John Podesta, who has a son stationed in Afghanistan.
Frayed relations between the Obama administration and the Karzai government loomed over the visit. The Afghan president rejected an invitation extended through the U.S embassy to meet Obama at Bagram.
"President Karzai said he would warmly welcome him if he comes to the palace but in no way he would go (to) Bagram to meet him," Abdul Karim Khurram, Karzai's chief of staff, told Reuters.
A U.S. official said the White House was not surprised that the proposed visit did not work on short notice.
Karzai has long expressed anger at civilian deaths in Afghanistan. He told the Washington Post in an interview in March that the war in Afghanistan was not fought with his country's interests in mind.
In a statement issued before Obama's arrival in Afghanistan, Karzai criticized the U.S. phone surveillance program, saying it violates his country's sovereignty. (Additional reporting by Jeff Mason in Washington and Jessica Donati and Hamid Shalizi in Kabul; Editing by Caren Bohan and Frances Kerry)