He pressed Mr Karzai to step up the fight against corruption and the drugs trade and invited the Afghan leader to visit Washington on May 12. Mr Karzai has pledged action against corruption, which infects every aspect of life in Afghanistan, as well as good governance and rule of law.
Mr Obama, whose relationship with Mr Karzai has been strained, urged his Afghan counterpart to "continue to make progress" on all fronts. Afghan analysts say the visit sent a clear message to Mr Karzai that the US expects him to act on promises to eradicate graft before visiting Washington.
"Obama has set some homework for Karzai, reminding him that the anti-corruption issue must be taken more seriously and that not enough has been done so far," analyst Waheed Mujda said.
Haroun Mir, director of Afghanistan's Centre for Research and Policy Studies, says Mr Obama's visit sent a "strong message" to Mr Karzai. "It was a strong message to president Karzai and his administration that the US cannot remain indifferent to the internal politics in Afghanistan," he said.
"I am sure before [Mr Karzai] goes to Washington in May he will have to take some proper measures to show that he has the intention and the political will to create some changes." The visit, which included briefings with US General Stanley McChrystal and US ambassador Karl Eikenberry, gave the president the chance to assess the progress of his new war strategy.
After dining with Mr Karzai at the presidential palace in Kabul, Mr Obama donned a leather bomber jacket to tell cheering troops at Bagram he was confident they would stop the Taliban from regaining power and halt Al Qaeda.