The March 13, 2018, visit, which was not announced in advance due to security concerns, comes as the United States is putting new resources into the more than 16-year-old war.
"But Afghan President Ashraf Ghani offered talks without preconditions with the Taliban insurgents last month, in what was seen by USA officials as a major overture from Kabul".
The US has a renewed focus on Afghanistan after years of drawdowns under former US president Barack Obama, and talk by top US generals of "not winning" and a "stalemate" in the seemingly intractable conflict.
Mattis' visit comes a week after United States intelligence officials told Congress that the Taliban was likely to continue to threaten Afghan stability in 2018, despite an improvement in Afghan security forces.
"We do look toward a victory in Afghanistan", he said, adding, "Not a military victory - the victory will be a political reconciliation" with the Taliban.
Mattis visited Kabul on Tuesday.
Mattis told reporters that the goal is to convince the Taliban militants that they can not win, which would hopefully push them toward reconciliation.
More than 3,000 additional United States forces have also arrived in Afghanistan to boost the training and advising of local troops.
Speaking to reporters, Mattis says that victory is still possible, meaning a political settlement with the Taliban could be in the cards.
"That is why at the Kabul Process conference we have presented [a] comprehensive proposal for peace with the Taliban and state-to-state talks with Pakistan", the presidential palace quoted Ghani as saying in a statement.
Mr. Trump, however, said on January 29 that he sees no basis for peace talks as long as the Taliban are "killing people left and right".
On the military front, US officials assert that years of effort to build a credible and effective Afghan army and air force are beginning to pay off.
For the first time, reporters were asked to withhold publishing their stories until arrival at the USA coalition headquarters in Kabul-a security concern dictated by the rocket attack against the Kabul airport a few hours after Mattis visited in September.
Mattis said the goal was to convince the Taliban insurgents that they could not win, which would hopefully push them towards reconciliation.
Thanks to the political process, Gen Mattis said the United States is now looking towards victory in Afghanistan.
Gen. Curtis Scaparrotti, the head of U.S. European Command, told a congressional panel on March 8, just days after visiting Afghanistan, that the Army's newly deployed brigade of advisers are expected to provide "a great boost for the mission" by operating more widely and closer to the front lines. Afghan forces, while "unsteady", probably will maintain control of most major population centers in 2018, he added.
However, the Taliban appears likely to miss that conference and have ruled out direct talks with the Western-backed government in Kabul, which they say is an illegitimate, foreign-imposed regime.