Mr Mattis however refused to give a firm number for how many troops US President Donald Trump would commit under a new strategy, just two years after NATO officially ended its post-9/11 combat role in Afghanistan.
Recent Taliban gains have shaken confidence in Afghanistan's future and talk of sending NATO troops in has stoked fears the alliance could get sucked back into an unwinnable war just when it faces a host of new threats including Russia, terrorism and cyberattacks.
"I don't put timelines on war, war is a fundamentally unpredictable phenomenon," the US defence secretary told reporters after meeting his counterparts from the 29-nation alliance.
"The bottom line is that NATO has made a commitment to Afghanistan for freedom from fear and terror, and freedom from terror demands that you can't let this be undone."
Citing both Afghanistan and "ungoverned spaces" in Syria and Iraq where the Islamic State group has flourished, the retired Marine general added: "You cannot say 'I am tired of it' and come home and then you get hit again."
'Stalemate' at best
NATO currently has 13,500 troops in Afghanistan in the Resolute Support mission to "train, advise and assist" Afghan troops.
Diplomatic sources said an increase of up to 3,000 was under considerations, while US officials say it might be nearer 4,000.
The United States, which once had more than 100,000 troops in Afghanistan, is preparing a new strategy for a war which has dragged on for 16 years and which even US generals concede is a "stalemate" at best.
NATO played the lead role in fighting the Afghan war from 2003 to the end of 2014, when it handed frontline duties to the Afghan military.
Mr Mattis said that after talks with the allies about 70 percent of the new plan's requirements were in place and he looked forward to bridging the remaining gap.
'The long haul'
NATO chief Jens Stoltenberg confirmed that the alliance would increase troop numbers, with 15 countries having pledged more, but stressed there would be no new combat role.
"We don't think it's going to be peaceful and no conflicts and no violence there this year or next year or in the near future, but we believe that Afghans (are) ... determined and committed to fight Taliban and to stabilise their own country," he said.
He insisted it was not wrong to end NATO's combat role in 2014, adding: "If anything, we should have done it before."
Mr Mattis however disagreed, saying there was "pretty much a consensus that we may have pulled our troops out a little too rapidly."
British Defence Secretary Michael Fallon said London would provide nearly 100 troops, on top of 500 already in Afghanistan.
"We're in it for the long haul," Mr Fallon told reporters.
Jim Mattis has stressed his new approach, due to be presented to Trump by mid-July, will have a broader "regional" emphasis, with no set timetable.
US President Trump has remained remarkably taciturn on Afghanistan, but this month gave Pentagon chief Jim Mattis authority to set troop numbers at whatever level he saw fit.
The US president used a summit last month to push NATO to do more to counter terror and for the allies to increase defence spending to ease the burden on Washington.
Terror, cyberattacks, Russia
Stung into action by Russia's intervention in Ukraine, NATO has embarked on its biggest military buildup since the end of the Cold War to face a more assertive Moscow.
Defence ministers discussed progress just as four "tripwire" battalions totalling 4,000 troops complete their deployment in the three Baltic states and Poland.
Stoltenberg warned that NATO must also step up its defences against cyberattacks after hackers caused chaos worldwide.
The global terror threat was also high on the agenda after NATO leaders agreed at last month's summit to join the US-led anti-IS coalition.
Stoltenberg said NATO would hold its next summit in Brussels in summer 2018.
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections.