Air Force One landed at Bagram Air Field, the main US base in Afghanistan, after an overnight flight from Washington.
Obama was scheduled to spend just a few hours on the base and had no plans to travel to Kabul, the capital, to meet with Hamid Karzai, the mercurial president who has had a tumultuous relationship with the White House.
Obama's surprise trip comes as the US and NATO withdraw most of their forces ahead of a year-end deadline. Obama is seeking to keep a small number of US troops in Afghanistan beyond 2014 to train Afghan security forces and conduct counterterrorism missions. But that plan is contingent on Karzai's successor signing a bilateral security agreement that Karzai has refused to authorise.
Obama's visit also was taking place against the backdrop of growing outrage 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.
At least 2,181 members of the US military have died during the nearly 13-year Afghan war and thousands more have been wounded. There are still about 32,800 US troops in Afghanistan, down from a high of 100,000 in mid-2010, when as Obama sent in additional soldiers to quell escalating violence.
This was Obama's fourth visit to Afghanistan as president, but his first since winning re-election in 2012.
He was expected to be briefed by US commanders in Afghanistan, speak to troops at Bagram and visit injured troops being treated at a base hospital.
As is typical of recent presidential trips to war zones, the White House did not announce Obama's visit in advance.
Media travelling with Obama for the 13-hour flight had to agree to keep the trip secret until the president arrived at the air base.
Obama has staked much of his foreign policy philosophy on ending the two wars he inherited from his predecessor, George W Bush.