Updated

President Obama made a surprise visit to Afghanistan this Memorial Day weekend, thanking troops for their fight to protect America and vowing to repay the sacrifice with lifetime commitments.

“We’re going to stay strong by taking care of your families,” the president told troops at Bagram Air Field in a roughly 25-minute speech. “We’re going to stay strong by taking care of our wounded warriors and our veterans. Because helping our wounded warriors and veterans heal isn’t just a promise, it’s a sacred obligation... I’m here to say that I’m proud of you.”

The visit took place amid outrage back in the United States over the treatment of America's war veterans. More than two dozen veterans' hospitals across America are under investigation over allegations of treatment delays and deaths, putting greater scrutiny on the Department of Veterans Affairs.

The agency already was struggling to keep up with the influx of forces returning home from Afghanistan and Iraq.

Obama arrived under the cover of darkness Sunday night to visit troops serving in the final months of their country’s longest war. He told service members that their valor is bringing the campaign to a “responsible end” and has Al Qaeda “on its heels in this part of the world.”

Obama, wearing a brown leather bomber jacket emblazoned with a U.S. presidential patch, also told the troops he is trying to get them out by year’s end -- to make good on a U.S.- NATO commitment to withdraw most of their forces by 2015.

He said he would probably make a decision “fairly shortly” on the county’s post-2014 presence in Afghanistan after talking with “folks on the ground.”

Obama was joined on the trip by Deputy National Security Adviser Ben Rhodes, who said before the president’s speech that Obama could announce his decision during a foreign policy address Wednesday at the U.S. Military Academy at West Point, N.Y.

The president is seeking to keep a small number of  troops in Afghanistan beyond 2014 to train Afghan security forces and conduct counter-terrorism missions. But that plan is contingent on Afghan President Hamid Karzai's successor signing a bilateral security agreement that Karzai has refused to authorize.

Obama didn’t meet with Karzai while in Afghanistan.

A White House official said no bilateral meeting with Karzai or palace visit was planned because the focus of the trip was to thank the troops.

However, Karzai was extended an invitation to come to the base that he declined, which didn’t surprise U.S. officials considering it was “on short notice,” the official said.

An senior administration official said Sunday that Obama called Karzai from Air Force One after departing Afghanistan, according to Reuters. In the call, Obama said he would inform Karzai's successor his plans on how many U.S. troops he wants to keep inside Afghanistan past 2014, the official said.

Obama looks forward to working with Afghanistan's next president after the runoff election is completed next month, the White House official also said.

Obama said the democratic election and the U.S. military’s efforts to thwart terrorism after the 9-11 terror attacks “has come at a heavy price.”

“Tomorrow is Memorial Day," he continued. "At bases here in Afghanistan and towns across America, we will pause and we'll pay tribute to all those who’ve laid down their lives for our freedom.”

At least 2,181 members of the U.S. military have died during the nearly 13-year Afghan war and thousands more have been wounded. There are still about 32,800 U.S. troops in Afghanistan, down from a high of 100,000 in mid-2010, when as Obama sent in additional soldiers to quell escalating violence.

Upon arriving in Afghanistan on Sunday, Obama was briefed by U.S. commanders and spoke to the troops after a performance by country music star Brad Paisley. He was also scheduled before departing to visit injured troops being treated at a base hospital.

This was Obama's fourth visit to Afghanistan as president but his first since winning re-election in 2012.

As is typical of recent presidential trips to war zones, the White House did not announce Obama's visit in advance. Media traveling with Obama for the 13-hour flight had to agree to keep the trip secret until the president arrived at the air base.

Also making the trip with Obama on Air Force One was National Security Adviser Susan Rice, senior White House adviser John Podesta, whose son is serving in Afghanistan, and adviser Dan Pfeiffer.

Obama also told the troops that as commander in chief he would maintain a strong military.

The president has staked much of his foreign policy philosophy on ending the two wars he inherited from his predecessor, George W. Bush.

The final American troops withdrew from Iraq in the closing days of 2011 after the U.S. and Iraq failed to reach a security agreement to keep a small American residual force in the country. In the years that have followed the American withdrawal, Iraq has been battered by resurgent waves of violence.

U.S. officials say they're trying to avoid a similar scenario in Afghanistan. While combat forces are due to depart at the end of this year, Obama administration officials have pressed to keep some troops in Afghanistan after 2014 to continue training the Afghan security forces and undertake counter-terrorism missions.

Pentagon officials have pushed for as many as 10,000 troops; others in the administration favor as few as 5,000 troops. Obama has insisted he will not keep any Americans in Afghanistan without a signed security agreement that would grant those forces immunity from Afghan law.

U.S. officials had hoped plans a post-2014 force would be well underway by this point. But Karzai stunned U.S. officials this year by saying he would not sign the security agreement even though he helped negotiate the terms. Karzai, the only president Afghans have known since the 2001 U.S.-led invasion to topple the Taliban's Islamic rule, was constitutionally barred from running for a third term this year.

The election to choose his successor was held this month, with the top two candidates advancing to the June runoff.

Both of those candidates, former Foreign Minister Abdullah Abdullah and ex-Finance Minister Ashraf Ghani Ahmadzai, have promised a fresh start with the West and pledged to move ahead with the security pact with the United States.

The Associated Press contributed to this report.