"The goal that I set -- to defeat al-Qaida and deny it a chance to rebuild -- is now within our reach," Obama said in a live televised address delivered from a military base near Kabul.
But even as the United States carries out a troop withdrawal, U.S. forces will continue to help the Afghans, "and fight alongside them when needed," he said in remarks from Bagram Air Base that began at 4:01 a.m. local time Wednesday (7:31 p.m. EDT Tuesday).
Obama's address, in front of two camouflage military vehicles, came a few hours after he arrived in Afghanistan in secret under cover of darkness and signed a pre-dawn "Enduring Strategic Partnership Agreement" with Afghan President Hamid Karzai meant to address the U.S. role even after the U.S.-led NATO alliance ends its combat mission in 2014.
"This time of war began in Afghanistan, and this is where it will end," Obama said.
"With faith in each other and our eyes fixed on the future, let us finish the work at hand and forge a just and lasting peace," he said on the first anniversary of the death of al-Qaida leader Osama bin Laden, shot and killed inside a private residential compound in Abbottabad, Pakistan, by U.S. Navy SEALs and CIA operatives in a covert operation Obama ordered.
The jihadist organization is responsible for the Sept. 11, 2001, terrorist attacks on the United States and numerous other mass-casualty attacks against civilian and military targets around the world.
Obama's speech did not lay out a new timetable for what he said was the goal for Afghanistan -- "a future in which war ends and a new chapter begins."
"Our troops will be coming home," Obama said. "Last year, we removed 10,000 U.S. troops from Afghanistan. Another 23,000 will leave by the end of the summer. After that, reductions will continue at a steady pace, with more and more of our troops coming home. And as our coalition agreed, by the end of 2014 the Afghans will be fully responsible for the security of their country."
He told Afghans, "As you stand up, you will not stand alone," saying the new agreement "establishes the basis for our cooperation over the next decade, including shared commitments to combat terrorism and strengthen democratic institutions."
"It supports Afghan efforts to advance development and dignity for their people. And it includes Afghan commitments to transparency and accountability, and to protect the human rights of all Afghans -- men and women, boys and girls," he said.
A senior administration official briefing reporters two hours before Obama's speech said "the strategic partnership itself does not commit the United States to any specific troop level or levels of funding in the future, as those are decisions that will be made in consultation with the U.S. Congress."
The pact calls for the administration to request money from Congress annually to pay for training of Afghan troops and other programs, including social and economic development assistance, the official said.
Obama also visited U.S. troops at Bagram, telling them the U.S. withdrawal would be an honorable one.
"We're not going to do it overnight. We're not going to do it irresponsibly," he said. "We're going to make sure that the gains, the hard-fought gains that have been made, are preserved.
"But the reason we're able to do that is because of you," Obama said. "The reason that the Afghans have an opportunity for a new tomorrow is because of you. And the reason America is safe is because of you."
Obama's Afghanistan visit -- the third of his presidency -- came as presumptive Republican presidential nominee Mitt Romney and GOP lawmakers have accused Obama of politicizing bin Laden's death.
The senior administration official briefing reporters denied the Afghanistan visit was timed to benefit Obama politically, noting Afghan and U.S. officials negotiated the settlement for nearly 20 months.
Karzai and Obama had both set a goal of having a deal in place before a NATO summit in Chicago May 20-21, the official said.
"And we had a goal of signing this agreement on Afghan soil to demonstrate our commitment to Afghan sovereignty and this new chapter in our relationship," the official said.
Romney said late Tuesday he was "pleased" Obama returned to Afghanistan.
"Our troops and the American people deserve to hear from our president about what is at stake in this war," he said.
Obama was to fly back to Washington within hours, and was scheduled to arrive at the White House at 1:40 p.m. EDT Wednesday, the White House said.