He spent time with US troops deployed at the sprawling base, serving them a traditional Thanksgiving meal of turkey and mashed potatoes.
The president also held a bilateral meeting with Afghan President Ashraf Ghani in which he announced he has restarted peace negotiations with the Taliban.
"The Taliban wants to make a deal — we’ll see if they make a deal. If they do they do, and if they don’t they don’t. That's fine," Trump was quoted as saying.
Trump said he believes the Taliban wants a ceasefire, according to the White House pool report.
"We're meeting with them and we're saying it has to be a ceasefire," he added. "They didn't want to do a ceasefire and now they do want to do a ceasefire. I believe it'll probably work out that way."
The announcement comes more than two months after Trump abruptly broke off peace talks with the Taliban following a bombing in Kabul that killed an American soldier. That ended a nearly year-long effort by the United States to reach a peaceful solution to the Afghan conflict with the militants.
Hopes were raised for a revival of the negotiations following a prisoner swap between Washington and Kabul last week.
The president also confirmed he would like to reduce the number of US troops in Afghanistan to 8,600. Around 12,000 to 13,000 troops remain stationed in the war-torn country - the site of the United States' longest-running war.
Trump campaigned in 2016 on withdrawing the US from foreign conflicts. In September, he tweeted that it "was not meant to be the job of our Great Soldiers" to act as "policemen" in Afghanistan.
The president told troops assembled in an aircraft hangar that there was "nowhere I’d rather celebrate this Thanksgiving than right here with the toughest, strongest, best and bravest warriors on the face of the earth."
In remarks broadcast on US media, the president praised the US military, saying "nobody beats our great army, navy, airforce, coast guard, marines."
It was Trump's first visit to Afghanistan. He made a similar trip last year to Iraq on Christmas — his first to a conflict zone.
Vice President Mike Pence last week visited US troops in Iraq during a surprise visit to the country, which has been rocked by a wave of anti-government protests.
---------------------------------------------------------------------------