An Afghan policeman stands guard near the site of a suicide bomb attack against a NATO convoy in Kandahar, Afghanistan. ( /Associated Press)

Stephen J. Hadley was national security adviser to President George W. Bush.

After 16 years of sacrifice in Afghanistan, President Trump is right to ask why we are there and what does it take to win.

The United States has vital national interests in Afghanistan. Since 9/11, preventing another terrorist attack on the U.S. homeland has remained our key objective. While the cost in lives and treasure has been too high, this objective has largely been achieved. But it has required a sustained U.S. troop presence, the active participation of our NATO allies and a close partnership with the Afghan government.

If the Trump administration now opts to draw down U.S. military forces, the NATO allies would go home and the Afghan state would likely collapse. The result would be a victory for the terrorists. It would undo the Trump administration’s recent success against the Islamic State in Syria and Iraq, and provide the Islamic State a haven in Afghanistan from which to foment attacks on the United States.

Instead, the Trump administration can deliver another major blow against terrorism. The Islamic State and al-Qaeda seek to expand their presence in Afghanistan, but virtually none of the Afghan groups — including the Taliban — support them. They can be defeated in Afghanistan just as they are being pushed out of Iraq and Syria. This natural extension of the Iraq/Syria campaign would help consolidate the victory against the Islamic State. But it will require U.S. counterterrorism forces to continue operating alongside Afghan security forces.

The challenge will then be to preserve the victory and help the Afghan people stabilize their country so that the Islamic State and al-Qaeda do not return. This can be done with a political/diplomatic strategy that seeks an inclusive settlement among all Afghan political factions while creating a more legitimate, popularly supported government that addresses the conflict’s root causes.

There has been some progress. Afghan President Ashraf Ghani is committed to reform. The Afghan defense forces are bravely fighting at tremendous cost. But the Afghan government must boost its legitimacy by broadening its base of popular support, fighting corruption and ensuring credible presidential elections in 2019. Continued U.S. support must be conditioned on these steps.

The big question is what to do about the Taliban. The answer: Test its interest in peace.

Defeating terrorist groups that threaten the United States does not include or require defeating the Taliban. The United States and NATO must make clear that they will fully support an Afghan-led political settlement involving all sectors of Afghan society — including the Taliban.

To give the Afghan government, military forces and society the confidence to enter into such a process, the Trump administration should authorize the modest increase in U.S. and NATO troop levels recommended by the local U.S. commander. The Afghan government can then credibly tell the Taliban that it will pay a heavy price for continuing to fight, but is welcome to participate in a political settlement.

If the Taliban prove unwilling, then the United States can still protect its interest by continued support for the Afghan government — conditioned on reform — and by further training, advising and assisting the Afghan armed forces so they can continue to keep the Islamic State and al-Qaeda from returning . Even at somewhat increased U.S. troop levels and associated costs, this is an acceptable price to pay to avoid terrorist attacks on our homeland. The Afghan government and its people will then have to outlast the Taliban’s appetite for the fight, just as the Colombian government was able to do with the Revolutionary Armed Forces of Colombia .

This new strategy will require U.S. leadership in two additional respects.

First, it will require a new U.S. approach to Pakistan that seeks to address its strategic concerns. This means supporting Pakistan more directly in dealing with its internal terrorist threat and the terrorist threat from Afghan territory. This means helping to restart a discrete dialogue between India and Pakistan on issues of mutual concern while encouraging greater regional economic integration. At the same time, Pakistan must show progress in cutting off terrorist activity against India and Afghanistan (including by the Haqqani network) — with targeted sanctions and other steps to raise the costs to Pakistan if it fails to do so.

Second, U.S. diplomatic efforts will need to focus on rebuilding a regional consensus on the need for a relatively peaceful and stable Afghanistan. To end the war, the United States should support regional mechanisms such as the Quadrilateral Coordination Group consisting of the United States, China, Pakistan and Afghanistan. More broad-based groups of Afghanistan’s neighbors and related regional actors should also be engaged. Russia and Iran should be offered a positive role as an alternative to their increasing support for the Taliban and other problematic groups.

A new Trump administration strategy along these lines can provide a clear victory over the Islamic State and al-Qaeda. It can contribute to a political outcome that can stabilize Afghanistan and preserve that victory. And it can be part of a broader strategy that the region so desperately needs if it is to escape the current cycle of terrorist violence.