Shanahan held talks with Ghani at the Presidential Palace on Monday to reaffirm his commitment to Afghanistan through implementation of President Trump's South Asia strategy.
"The leaders discussed a broad range of defence issues, including the importance of the US-Afghanistan security relationship and of achieving a political settlement to the war that ensures Afghanistan is never again used as a safe haven from which terrorists can plan and launch terrorist attacks against the United States, our interests, and our allies," said Pentagon Spokesperson Cmdr Sean Robertson.
During the meeting, Shanahan praised the sacrifices made by Afghan and Coalition troops, and reaffirmed America's continued support to Afghan forces as they lead the fight to defend their country.
Shanahan made a surprise trip to Afghanistan on Monday, his first-ever visit to the country where US troops have been stationed for 17 years.
President Donald Trump reportedly wants to cut in half the 14,000 American troops in Afghanistan, and the Taliban leaders have made a US withdrawal a key condition in peace negotiations.
Shanahan told reporters on Monday that he had no orders to reduce the American troop presence. He said that while the US had a key role to play, it is ultimately up to Afghans to find peace.
"The Afghans have to decide what Afghanistan looks like. It's not about the US, it's about Afghanistan," he said.
The Acting Defense chief's visit comes after the US held major talks with the Taliban officials in Qatar last month in an attempt to end the 17-year conflict.
US special envoy Zalmay Khalilzad, who is leading the talks, has expressed hope of finding a deal before Afghan presidential elections scheduled for July.
In a series of tweets after six days of talks with the Taliban representatives in Doha last month, Khalilzad said the US has made "significant progress" in its peace talks with the Taliban.
"We have a draft of the framework that has to be fleshed out before it becomes an agreement. The Taliban have committed, to our satisfaction, to do what is necessary that would prevent Afghanistan from ever becoming a platform for international terrorist groups or individuals," Khalilzad said at the time.
Since being appointed in September, Khalilzad has met with all sides in an attempt to end America's longest war in which the US has lost over 2,400 soldiers.
The US is expected to start a second round of talks with Taliban officials on February 25 in Qatar, where they have their political office.
The Afghan Taliban, however, has said that despite the ongoing talks with the US and other regional powers, it had "not yet reached" any conclusion that would entail an immediate end to hostilities against America and its allies.
The Taliban are holding talks with the United States "on their own initiative", Taliban spokesman Zabiullah Mujahid was recently quoted as saying by a TV channel.
The Taliban control nearly half of Afghanistan, and are more powerful than at any time since the 2001 US-led invasion after the 9/11 terror attacks in 2001.
Meanwhile, Indian-American Congressman Ro Khanna said that the US should continue supporting the Afghan government financially and diplomatically after leaving and include them in the peace process.
"We should continue supporting the Afghan government financially and diplomatically after leaving and include them in the peace process. The Afghans must eventually earn domestic legitimacy themselves, though," he said in an op-ed in USA Today.
Khanna said the biggest threat to democracy was not the Taliban, but staying economically competitive with authoritarian superpowers like China.
Responding to critics who argue that after the US withdrawal the Taliban might steamroll the Afghan government and then harbour terrorists, Khanna said preventing that outcome did not require a permanent US troop presence.
"Deterrence works. The Taliban should understand that the United States will use overwhelming force again if they harbour terrorists who directly threaten our homeland. Moreover, other 'ungoverned territories' exist where terrorists can operate. There, we conduct counterterrorism from the air without troop deployment," Khanna said.