Obama made a covert night time trip from the White House to Bagram Air Base aboard a darkened Air Force One on a visit meant to hail the sacrifices of US soldiers in Afghanistan ahead of the US Memorial Day weekend.
But his visit of only a few hours provoked a new spat with outgoing Afghan President Hamid Karzai with whom Obama has an extremely strained relationship. US officials said Obama offered to see the Afghan leader at the sprawling Bagram base but decided not to go to his palace in central Kabul.
They did not say how much notice they had given the Afghan leader of Obama's arrival. Karzai interpreted Obama's invitation as a snub, saying in a pointed statement that "the government of Afghanistan is prepared to warmly welcome the US president in the presidential palace, but it does not intend to go to Bagram to meet Obama."
A US official summed up the latest disconnect in the dysfunctional relationship between Washington and a man it once hailed as Afghanistan's saviour, by saying: "We're not surprised that it didn't work on short notice."
Barack Obama visited Afghanistan only for a few hours
Obama also avoided Ashraf Ghani and Abdullah Abdullah, the two candidates in a June runoff election to become the next president, with aides saying that he did not want to insert himself in Afghanistan's "election season."
Obama renewed his commitment to a limited presence in Afghanistan for US and NATO troops after the withdrawal of combat forces at the end of the year. He said he hoped that the new Afghan president would agree to a bilateral security agreement mandating the mission, which Karzai has refused to sign.
US officials believe either Ghani or Abdullah will do so. At the end of a war which Obama escalated after taking office, he argued the steep sacrifices of US troops - more than 2,300 have died - are being rewarded.
"After more than a decade of war we are at a pivotal moment," Obama told a hangar full of cheering US servicemen and women. "By the end of this year, the transition will be complete and Afghanistan will take full responsibility for their security. "Our combat mission will be over.
America's war in Afghanistan will come to a responsible end."