Hours after Mattis touched down in Kabul, militants fired high explosive ammunition including mortar rounds near the main airport and detonated several suicide vests in an attack claimed by both the Taliban and Islamic State.
"Our presence together in Afghanistan reflects our continuing commitment to bringing stability and peace", the North Atlantic Treaty Organisation chief said at a joint press conference attended by the head of the Pentagon and president Ghani.
At a joint news conference with Ghani at the presidential palace, Mattis and Stoltenberg renewed their commitment to Afghanistan, and expressed determination to stop the country becoming a safe haven for terrorists.
The visits by Mattis and Stoltenberg come after US President Donald Trump allowed the deployment of another 4,000 US troops in Afghanistan.
Mattis held closed-door talks with Afghan President Ashraf Ghani and NATO Secretary-General Jens Stoltenberg in an unannounced trip to Kabul, his first to the country since the Trump administration announced its new strategy for Afghanistan.
Earlier this week SIGAR criticised USA efforts to train Afghanistan's security forces, saying they were being hampered by slapdash instruction, shoddy oversight and failures in governance.
There are approximately 11,000 US service members in Afghanistan, most of whom are tasked with training and advising local forces, while a small contingent of special operations troops are conducting counterterrorism operations against ISIS in the east. At one point, the Afghan forces called in a United States airstrike.
Stoltenberg said on Wednesday that more non-U.S. troops were also on their way to Afghanistan, adding to the current 5,000 personnel.
Promising a more "holistic" approach without fixed timetables and involving other countries in the region, he said the Taliban would have to learn they could not defeat the government, Reuters reported.
The U.S. responded to the attack by backing the Afghan forces with airpower.
"With President Trump's recent announcement of his strategy to counter terror and stabilize South Asia, Afghanistan's enduring partnership with the United States and the global community has been renewed and redirected", he said.
The strategy will also make greater use of U.S. air power to support Afghan forces and strike the Taliban, a strategy that carries the risk of an increase in civilian casualties.