An Afghan rides past a painting aimed to combat corruption in Kabul. (Wakil Kohsar/AFP/Getty Images)

Stephen J. Hadley, the U.S. national security adviser from 2005 to 2009, is chair of the United States Institute of Peace board of directors. Andrew Wilder is the organization’s vice president for South and Central Asia programs.

The horrific bombings in Kabul this past week that killed and wounded hundreds of civilians are a grim reminder that there are enormous challenges ahead in Afghanistan. But a recent 10-day visit to the region convinced us that there is also still a real possibility of a path to peace.

Perhaps the most troubling thing we learned from senior Afghan and Pakistani officials during our visit was that Afghanistan is once again becoming a haven for transnational terrorist groups, including the brutal Islamic State. With much of the region in chaos, few U.S. allies have the political will, public support and ground forces to fight the terrorists. Afghanistan is a notable exception.

Last year’s political and security transitions produced a reformist unity government led by President Ashraf Ghani and Chief Executive Abdullah Abdullah and the successful assumption of security responsibility by Afghan security forces. But the simultaneous withdrawal of more than 120,000 coalition troops and dramatic reduction in international military and civilian assistance produced a severe economic crisis. Pakistan’s military operation in North Waziristan, coming right after the security transition in Afghanistan, pushed thousands of hardened militants across the border at a moment when Afghan forces were least able to handle them. Many fighters moved into northern Afghanistan, long a relatively quiet area.

The Afghans, still struggling with a long-standing Taliban-led insurgency, are now fighting militants drawn from throughout Central Asia, Pakistan, the Caucasus and the Middle East — something not envisioned in the planning for the security transition. Afghan forces are fighting bravely, mostly holding their own, but are taking heavy casualties.

Ghani’s courageous outreach to Pakistan dramatically improved relations between the two countries, at least until the attacks of this weekend. This initiative came while Pakistan was still reeling from the devastating December attack by the Pakistani Taliban (the TTP) on the Army Public School in Peshawar that killed more than 130 children. This attack plus Ghani’s outreach seem to have convinced Pakistan to support Afghan reconciliation and to sponsor direct discussions between Taliban and Afghan government representatives. The most recent meeting, on July 7 in Murree, Pakistan, with China and the United States observing, could become a full-fledged reconciliation process. We believe the internal Taliban power struggle and last weekend’s attacks will delay things, perhaps for months, but have not killed the chance for talks.

Pakistan now seems to accept that it needs a stable Afghanistan that is not a terrorist safe haven. As one senior Afghan official told us: “The TTP changes things for Pakistan. The more the Pakistanis support the Haqqani Network and the Taliban to weaken the Afghan state, the more safe havens there will be in Afghanistan for the TTP to attack Pakistan.”

But Pakistan clearly wants to control the reconciliation process and retain its influence over the Taliban. Afghans believe, with some justification, that Pakistan has doubled down on its material support to the Taliban during the current fighting season — both to hedge its bet on reconciliation and to strengthen its negotiating position. So, perversely, the prospects for peace and the pace of conflict have increased in tandem.

The Taliban appear to be under pressure. Pakistan seems to be pushing them toward reconciliation and the Afghan security forces have not collapsed, as some expected, following the coalition drawdown. The announcement of Taliban leader Mohammad Omar’s death — two years after the fact — not only exacerbates growing internal divisions but also undermines the movement’s legitimacy by raising questions about whether the group is simply an agent of Pakistan. And the arrival of the Islamic State introduces a potentially dangerous rival.

The Afghan government needs to take advantage of these developments by renewing its call for the Taliban to leave the insurgency and reconcile. The Pakistanis and Afghans to whom we talked all believe that the reconciliation process should be pursued despite considerable skepticism that it can succeed.

Success will depend largely on whether the Afghan unity government can dramatically improve its performance, communicate effectively to its people and provide some level of economic growth and better security and military effectiveness. But the United States and other friends of Afghanistan can take four steps to buy time for the Afghan government and to put pressure on the Taliban.

●First, increase U.S. and international diplomatic pressure on Pakistan to bring all Taliban elements to the table and make peace with Afghanistan.

●Second, provide short-term economic stimulus focused on job creation combined with governmental reforms. Even then, the improved public confidence the economy needs will depend as much if not more on improvements in governance and security.

●Continue the current level of financial support for the Afghan security forces, combined with an expanded U.S. mission to train, advise and assist those forces. These steps are needed to maintain both the morale of the Afghan forces and the military pressure that has helped bring the Taliban to the table.

●Develop an Afghan counterterrorism platform in the country — supported by adequate U.S. intelligence, surveillance and reconnaissance and close air support — to deny safe haven to terrorist groups in Afghanistan and the region and to encourage reconciliation.

We are not advocating a return to U.S. combat operations or a U.S. military buildup. But our suggestions will undoubtedly require a U.S. military presence closer to current levels than the 1,000-person Kabul-based force previously planned for post-2016. The exact size of the force should be mission-driven, with the theater commander having the flexibility to determine its composition, deployment and use.

We believe that, despite all the challenges, peace can come to Afghanistan. But both Afghanistan and the United States must do their part.