In a reference to the destruction of New York's World Trade Center on Sept. 11, 2001, he added, "As we emerge from a decade of conflict abroad and economic crisis at home, it is time to renew America ... 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 spoke for less than 15 minutes, beginning at 4 a.m. in Afghanistan, 7:30 p.m. on the East Coast of the United States. Minutes later, Air Force One was on its way back to Washington.
Obama flew to the site of America's longest war not only as commander in chief but also as an incumbent president in the early stages of a tough re-election campaign. Nor were the two roles completely distinct.
His presence was a reminder that since taking office in 2009, Obama has ended the war in Iraq and moved to create an orderly end for the U.S. combat role in Afghanistan.
In the political realm, he and Vice President Joe Biden have marked the one-year anniversary of bin Laden's death by questioning whether Republican challenge Romney would have ordered the daring raid that penetrated the terrorist leader's Pakistan hide-out. Republicans are accusing the president of trying for political gain from the event, and Romney is insisting that he would indeed have ordered U.S. forces into action.
The deal signed with Karzai does not commit the United States to any specific troop presence or spending. But it does allow the U.S. to potentially keep troops in Afghanistan after the war ends for two specific purposes: continued training of Afghan forces and targeted operations against al-Qaida. The terror group is present in neighboring Pakistan but has only a nominal presence inside Afghanistan.
Obama said the agreement was meant in part to pay tribute to the U.S. troops who have died in Afghanistan since the war began. He also underlined his message to Afghans.
"With this agreement I am confident that the Afghan people will understand that the United States will stand by them," he said.
Karzai said his countrymen "will never forget" the help of U.S. forces over the past decade. He said the partnership agreement shows the United States and Afghanistan will continue to fight terrorism together. The United States promises to seek money from Congress every year to support Afghanistan.
To the troops, he readily conceded continued hardship.
"I know the battle's not yet over," he said. "Some of your buddies are going to get injured. And some of your buddies may get killed. And there's going to be heartbreak and pain and difficulty ahead." He added that his administration is committed to ensuring that once the war is over, veterans will be given their due.
Officials have previously said as many as 20,000 U.S. troops may remain after the combat mission ends, but that still must still be negotiated.
The president's Tuesday night address was coming exactly one year after special forces, on his order, began the raid that led to the killing of bin Laden in Pakistan.
Since then, ties between the United States and Afghanistan have been tested anew by the burning of Muslim holy books at a U.S. base and the massacre of 17 civilians, including children, allegedly by an American soldier.
Obama had gone twice before to Afghanistan as president, most recently in December 2010, and once to Iraq in 2009. All such trips, no matter how carefully planned, carry the weight and the risks of considerable security challenges. Just last month, the Taliban began near-simultaneous assaults on embassies, government buildings and NATO bases in Kabul.
Besides the U.S. troops in Afghanistan, there are 40,000 in coalition forces from other nations.
Associated Press writers Anne Gearan and David Espo, Deputy Director of Polling Jennifer Agiesta and News Survey Specialist Dennis Junius contributed to this story.