President Barack Obama laid out his plan to end the war in Afghanistan during a surprise visit to the country that U.S. troops, he said, will leave by the end of 2014. Speaking at Bagram airbase south of Kabul just before dawn on Wednesday -- prime time Tuesday night for television viewers back home in the United States -- Obama said that "this time of war began in Afghanistan, and this is where it will end, with a just and lasting peace."

The president had landed in secret at Bagram just hours earlier, on the first anniversary of the death of Osama bin Laden, who was killed on May 2, 2011, in Abbottabad, Pakistan, by U.S. Navy SEALS. "The goal that I set to defeat al Qaeda and deny it the chance to rebuild is now within our reach," Obama said.

The president said the U.S. remains committed to pulling out 23,000 troops from Afghanistan by the end of the year, and it will turn security over to the Afghan government by the end of 2014.   

Obama also announced that NATO will set a goal this month for Afghan forces to lead combat operations in the country next year. During the president's visit, Obama and Afghan president Hamid Karzai signed an agreement outlining cooperation between the two countries after the withdrawal of U.S. and allied forces.

Earlier, speaking to troops at Bagram, Obama thanked them and said "I could not be prouder of you. There's a light on the horizon because of the sacrifices you've made."

Addressing the nation live, with two desert-camouflaged military vehicles behind him, the president said "we have traveled through more than a decade under the dark cloud of war. Yet here, in the predawn darkness of Afghanistan, we can see the light of a new day on the horizon."

In a speech that seemed to announce one of the themes of the campaign for the November election, the president then shifted focus from the wars in Iraq and Afghanistan to domestic issues: "As we emerge from a decade of conflict abroad and economic crisis at home, it is time to renew America. An America where our children live free from fear and have the skills to claim their dreams. A united America of grit and resilience, where sunlight glistens off soaring new towers in downtown Manhattan, and we build our future as one people, as one nation," he said.