Discuss as:

President Obama goes to Afghanistan to sign post-war agreement

President Obama speaks from Afghanistan about the post-war deal he just signed with Afghan President Hamid Karzai.

President Barack Obama and Afghan President Hamid Karzai signed an agreement that provides a framework for a lasting U.S. commitment to Afghanistan after the long and unpopular war comes to an end.

Standing in front of Afghan and U.S. flags, Obama and Karzai signed the Strategic Partnership Agreement just after midnight local time. Obama called it "a historic moment for our two nations," adding that the deal with Afghanistan allows the U.S. to wind down the war, but still stand by Afghanistan and its people.

"Neither Americans nor the Afghan people asked for this war, yet for a decade we've stood together," Obama said. "Today, with the signing of the strategic partnership agreement, we look forward to a future of peace. Today we're agreeing to be long term partners."

Karzai says the postwar agreement will seal an "equal partnership" between Afghanistan and the United States. According to pool reports, Karzai thanked the United States for helping the people of Afghanistan.

Obama and Karzai signed the agreement at the presidential palace in Kabul shortly after the U.S. president arrived in Afghanistan on Tuesday on an unannounced visit.

The partnership spells out the U.S. relationship with Afghanistan beyond 2014, covering security, economics and governance. The deal is limited in scope and essentially gives both sides political cover: Afghanistan gets its sovereignty and a promise it won't be abandoned, while the U.S. gets to end its combat mission but keep a foothold in the country.

"When it comes to an enduring U.S. presence, President Obama has been clear: we do not seek permanent military bases in Afghanistan," a statement from the White House said. "Instead, the Strategic Partnership Agreement commits Afghanistan to provide U.S. personnel access to and use of Afghan facilities through 2014 and beyond."

The agreement opens the possibility for continued training of Afghan forces and targeted operations against al-Qaida, which is present in neighboring Pakistan but has only a nominal presence inside Afghanistan.

President Barack Obama is in Kabul to sign a 10-year security agreement with Afghanistan. NBC's Chuck Todd and Jim Miklaszewski report.

Obama planned to be on the ground for about seven hours in Afghanistan, where the United States has been engaged in war for more than a decade following the Sept. 11, 2001, attacks. The trip carries major symbolic significance for a president seeking a second term and allows him to showcase what the White House considers the fruit of Obama's refocused war effort: the killing a year ago of 9/11 mastermind Osama bin Laden.  

Air Force One touched down late at night local time at Bagram Air Field, the main U.S. base here.   

Media traveling with Obama on the 13-hour flight had to agree to keep it secret until Obama had safely finished a helicopter flight to the nation's capital, Kabul, where Taliban insurgents still launch lethal attacks.   

For Afghans, death of bin Laden hasn't ended their problems

Obama will also give a speech designed to reach Americans in the U.S. at 7:30 p.m. ET.

His war address will come exactly one year after special forces, on his order, began the raid that led to the killing of bin Laden in Pakistan.   

Kevin Lamarque / Reuters

President Barack Obama shakes hands with U.S. Ambassador to Afghanistan Ryan Crocker upon his arrival at Bagram Air Base in Kabul, Afghanistan May 1, 2012.

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's overarching message will be that the war is ending on his watch but the U.S. commitment to its ally is not.  

Read the transcript of Obama's remarks from Bagram Air Base

Politics, too, set the tone for what the White House hoped would be a positive message and image for Obama: the commander in chief setting a framework to end the war while reassuring Afghanistan, on its soil, it will not be abandoned.   

At home, Obama's Republican opponent, Mitt Romney, has retorted to the Obama campaign's suggestion that Romney might not have gone after bin Laden as Obama did.   

Bin Laden in hiding: Hatching horrific plots despite crippling attacks on al-Qaida

"Even Jimmy Carter would have given that order," Romney said of the Democratic president ousted after one term.    Obama has tried to portray inconsistency in Romney's position on the merits of targeting bin Laden. Without mentioning Romney by name, Obama has said he has been consistent and if others have not, "let them explain it."   

Obama aides said the anniversary of bin Laden's killing is not a focus of the trip. But they do not mind that Obama's mission will serve as a reminder, six months before Election Day.   

Sen. John McCain, R-Ariz., released a statement saying he was pleased the president had traveled to Afghanistan to hear directly from the troops on the ground about the progress made there. McCain said there is a need for the United States to remain engaged in Afghanistan in the coming years.

"I hope the President's speech tonight will emphasize the degree of our commitment in Afghanistan, rather than the plans for withdrawal," McCain added.

More than 1,800 U.S. forces have been killed and 15,700 more have been wounded in Afghanistan.   

The wars in Afghanistan and Iraq combined have cost almost $1.3 trillion. And public support for keeping troops in Afghanistan seems lower than ever.   

Obama has 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.   

Still, it would have been unusual for Obama to sign the "strategic partnership" agreement without Karzai at his side.   

Nearly a year after Osama bin Laden was killed by U.S. forces, President Barack Obama, Admiral Mike Mullen, and Secretary of State Hillary Clinton spoke exclusively to NBC's Brian Williams and reflected on the raid. The hour-long special, 'Inside the Situation Room,' airs Wednesday, May 2 at 9pm/8c on NBC's Rock Center.

The deal is essential for locking in America's commitment and Afghan's sovereignty when the post-war period comes. Negotiations have dragged as Afghan officials have demanded specific assurances, financial and otherwise.   

Want a bin Laden brick? Pieces of Abbottabad compound sell for a nickel

Both sides have scrambled to get a deal before the NATO conference in Chicago later this month. Negotiators seemed to clear the way for Obama and Karzai by finding agreement over the conduct of night raids and authority over detainees.   

The president was to travel back from Kabul to the Bagram base to spend some time with troops.   

He was then to give his speech in a straight-to-camera delivery reminiscent of an Oval Office address, before flying back to the U.S. He is expected back in Washington on Wednesday afternoon.   

The United States has 88,000 troops in Afghanistan. An additional 40,000 in coalition forces remain from other nations.   

Obama has already declared that NATO forces will hand over the lead combat role to Afghanistan in 2013 as the U.S. and its allies work to get out by the end of 2014.   

One important unsettled issue, however, is how many U.S. troops may remain after that.   

U.S. officials are eying a residual force of perhaps 20,000, many in support roles for the Afghan armed forces, and some U.S. special forces for counterterror missions. The size and scope of that U.S. force -- if one can be agreed upon on at all, given the public moods and political factors in both nations -- will probably have to be worked out later in a separate agreement.   

Nearly a year after Osama bin Laden was killed by U.S. forces, President Barack Obama spoke exclusively to NBC's Brian Williams inside the Situation Room and reflected on the raid. The full report airs Wed., May 2 at 9pm/8c on NBC's Rock Center.

Support for keeping American troops in Afghanistan is dropping all along the political spectrum, a new Pew Research poll says. And just 38 percent of people say the military effort is going well, down from 51 percent only a month ago.   

Overall, polling shows, Obama gets favorable marks compared to Romney in handling terrorism, and the president's public approval for his handling of the Afghan war has hovered around 50 percent of late.   

The trip allows Obama to hold forth as commander in chief in the same week he plans to launch his official campaign travel with rallies in Virginia and Ohio.   

"We've spent the last three-and-a-half years cleaning up after other folks' messes," Obama said at a fundraiser last weekend. "The war in Iraq is over. We're transitioning in Afghanistan. Al-Qaida is on the ropes. We've done what we said we'd do."

This article includes reporting from The Associated Press, pool reports from the press corps traveling with the president, and msnbc.com staff.

More world news from msnbc.com and NBC News:

Follow us on Twitter: @msnbc_world