After a brief meeting with President Hamid Karzai at the presidential palace in Kabul, Mr Obama praised recent steps in the military campaign against insurgents but said Afghans needed to see conditions on the ground get better.
"Progress will continue to be made, but we also want to make progress on the civilian front," Mr 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," the President added.
Mr Obama also invited Mr Karzai to visit Washington on May 12, the White House said.
Mr Karzai promised that his country "would move forward into the future" to eventually take over its own security, and thanked Mr Obama for the American intervention in his country.
The trip, its secrecy forced by security concerns, was an extraordinary capstone to a momentous week in Obama's presidency.
He achieved the most ambitious domestic policy initiative in decades with a historic health care overhaul and scored first major foreign policy achievement with a significant new arms control treaty with Russia.
Mr Obama landed in Afghanistan for a stay of just a few hours, all in darkness, after an overnight flight from Washington. He flew by helicopter from Bagram airfield to the capital, where Mr Karzai greeted him at the palace.
It was the US President's second stop in a war zone as commander in chief, coming about a year after a similarly secretive trip to Iraq.
The trip was intended to let Mr Obama tell Mr 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 US also wants Mr Karzai to halt cronyism and rewards for warlords in government hiring and to create an effective, credible judicial system.
The White House insisted that Mr Karzai's cabinet participate in most of the meetings with Mr Obama.
The cabinet includes a number of ministers favoured by the US, including the heads of finance, interior and defence, whom the Obama administration wants to empower as a way of reducing the influence of presidential cronies.
Some talented Afghan administrators have complained
that Mr Karzai marginalised them in an attempt to solidify his powers.