President Barack Obama on Tuesday made his third unannounced trip to Afghanistan – the first in more than two years — this time to sign a strategic pact that will guide U.S. relations with the country for the next decade. The pact, negotiated over the past 20 months, could be key to the withdrawal of U.S. forces from Afghanistan because it establishes guidelines for the relatively small force that will remain behind to continue training Afghan security forces.

“Today, I signed a historic agreement between the United States and Afghanistan that defines a new kind of relationship between our countries – a future in which Afghans are responsible for the security of their nation, and we build an equal partnership between two sovereign states; a future in which the war ends, and a new chapter begins,” Obama said in a nationally televised address from Bagram Air Force Base on Tuesday evening Washington time, around 4 a.m. in Kabul. “My fellow Americans, we have traveled through more than a decade under the dark cloud of war. Yet here, in the pre-dawn darkness of Afghanistan, we can see the light of a new day on the horizon. The Iraq War is over. The number of our troops in harm’s way has been cut in half, and more will be coming home soon. We have a clear path to fulfill our mission in Afghanistan, while delivering justice to al Qaeda.”

There are currently more than 90,000 U.S. troops in Afghanistan and the U.S. is expected to draw down that number to 65,000 by the end of 2012 and to less than 20,000 by the end of 2014. Obama made no firm pledge on the number of soldiers who will remain over the next decade to further train Afghan security forces and hunt down al Qaeda and White House officials said that decision won’t be made until the next draw down is complete at the end of this summer. “The [continued U.S.] presence will be hugely important—not only for specific help with intelligence, air transport, and other key capabilities, but for reassurance,” says Michael O’Hanlon, a foreign policy expert at the Brookings Institution. “Afghanistan is a weak state near powerful neighbors who will be less tempted to run amok and wreak havoc there with a continued U.S./NATO presence.”

The trip comes after a rocky few months for U.S.-Afghan relations. In late February the inadvertent burning of Korans by U.S. forces set off mass protests and killings of NATO forces across Afghanistan. An AWOL U.S. soldier’s alleged slaughter of 17 Afghan civilians in mid-March made matters worse. Despite NATO assurances that the security situation has improved in Afghanistan, the secure, so-called Green Zone in Kabul has twice come under attack in recent months by insurgents firing mortars and rocket propelled grenades. Obama’s brief visit, conducted under the cover of the night, helped ensure security for Air Force One to land at Bagram Air Force base and for Marine One to land in Kabul.

Earlier that night when signing the agreement with Afghan President Hamid Karzai, whom Obama greeted as “my friend,” the President hailed the “historic moment for our two nations.” Also present at that midnight local time event was U.S. Ambassador to Afghanistan Ryan Crocker; the senior allied commander in Afghanistan John Allen; Senate Armed Service Committee Chairman Carl Levin, a Michigan Democrat; Senator Jack Reed, a Rhode Island Democrat; White House Chief of Staff Jack Lew; and senior Obama adviser David Plouffe. “I’m here to affirm the bond between our two countries and to thank Americans and Afghans who have sacrificed so much over these last ten years,” Obama said. “Neither Americans nor the Afghan people asked for this war yet for a decade we’ve stood together. 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.”

The trip also comes on the year anniversary of the killing of Osama bin Laden. Republicans and some Navy Seals have criticized the President for taking one too many victory laps on the killing, making it a political issue for the November presidential elections. Conservative news site The Drudge Report ran a headline for the President’s rumored visit reading, “Obama Spikes Ball in Kabul.” Republican presidential nominee-presumptive Mitt Romney marked the anniversary with a press conference and campaign event with former New York Mayor Rudy Giuliani. “I believe [Obama] certainly has a right to take credit for [the Osama bin Laden mission],” said Giuliani, who was mayor of the city during the Sept. 11 attacks, “but he shouldn’t use it in a negative campaign.”

White House officials said the timing of the visit was based on Obama and Karzai’s desire to see the 10-page strategic partnership agreement signed before the NATO summit in Chicago later this month. The agreement, which took nearly two years to negotiate, was only concluded a couple of weeks ago and Obama had pledged to sign it on Afghan soil before the summit, which left only a small window of time for the trip. Plus,”the President always planned to spend today [the one-year anniversary of bin Laden’s death] with the troops,” a senior official told reporters on a call. “What better way to spend it than by thanking those who made it happen?”

When asked if the President is “spiking the ball,” Senator John McCain of Arizona, who was the 2008 Republican nominee, said he actually welcomed Obama’s trip given that it’s been more than a year since the President has delivered a big speech about the ongoing war. ““I am pleased that the President has traveled to Afghanistan,” McCain said in a statement. “This is a significant opportunity for him to hear directly from our military commanders and troops on the ground about the significant progress we are making in this fight.”

After the signing, Obama returned to Bagram Air Force Base where he addressed a hangar full of U.S. troops and giving a televised address before departing. In his speech to the troops, the President thanked them for their service, praising those who signed up after 9/11. “Slowly and systematically we have been able to decimate the ranks of al Qaeda and a year ago we were able to finally bring Osama bin Laden to justice,” Obama said to cheers. “That could’ve only happened because each and everyone of you in your own way were doing your jobs.”

There remains much to be done in Afghanistan. With Karzai constitutionally term-limited, Afghans will have to not only pick his successor in 2014, but grapple with an electoral process that’s been dogged by security problems and corruption allegations. “The pact helps psychologically and politically but only somewhat—we’ll need more, ongoing progress on issues like getting ready for the 2013/2014 Afghan political transition and continuing the hand off of main security responsibility in key regions to Afghan forces, to build up positive momentum and a sense of success,” O’Hanlon says. Suffice to say, this is not likely to be the last surprise trip a U.S. President makes to Kabul.