Pakistan has largely escaped the ghastly destruction of the civil wars in the Middle East—despite its continuing struggle with homegrown Islamist extremism and terrorism. Since September 11, 2001, Pakistani governments have tried to fly under the radar, attracting minimal international pressure even though its territory has been used as a sanctuary by the Afghan Taliban, al-Qaeda, Kashmiri militants, and other extremists from the region. But the US and NATO have now begun to express their concerns.

The international community is worried because there is a growing domestic political crisis in this nuclear-armed nation that is fueled by extremists at home and by a foreign policy that involves harboring insurgent groups, which has become unacceptable to the world as well as to Pakistan’s neighbors in South Asia. President Donald Trump and NATO have clearly signaled they will no longer tolerate the Pakistani army’s alleged duplicity—that while it fights those terrorists who threaten the state of Pakistan, it shelters outside groups like the Afghan Taliban, which does its fighting elsewhere. Pakistan’s response is to accuse the Americans of looking for scapegoats, having lost the war in Afghanistan.

The Pakistani “miltablishment”—a name coined by the weekly Friday Times that describes the alliance between the army, its all-powerful Inter-Services Intelligence agency (ISI), the senior judiciary, the government bureaucracy, and some politicians—is now deeply at odds with itself. A power vacuum has developed into which has stepped a bewildering array of Islamist extremists. The future of Pakistan itself is at risk.

During a harrowing three weeks in November, a small, almost unknown fringe group of well-armed Sunni militants blocked the capital Islamabad’s main highway and demanded the resignation of the justice minister and other officials for trying to change the stringent blasphemy law and for being sympathetic to the Ahmadis, a Muslim sect controversially proscribed by the state. The group, which calls itself Tehreek-e-Labaik (TEL), or the Movement in Service to the Finality of the Prophet, then ordered its followers to block major roads all over the country. For several days, traffic across Pakistan ground to a halt. Six or seven people were killed and more than two hundred were injured.

As public speculation grew about which part of the “miltablishment” was allowing food, water, and blankets to reach the militants, the government seemed paralyzed—unwilling to act decisively or to send in the 8,000 police officers at its disposal to arrest those mounting the blockades, who never numbered more than 3,000 in Islamabad. At long last, the government called in the army to clear the barricades. But none of the militants was arrested, and when the army arrived, it was to broker a deal, which the militants quickly accepted—and to which the government, too, was obliged to accede.

The entire episode had the air of a well-rehearsed drama. The army and the government gave in to all the militants’ demands, including the resignation of the justice minister, the release of all the group’s prisoners, compensation to the protesters, and further entrenchment of the harsh blasphemy law. An ISI general signed the agreement as its “guarantor.”

The BBC World Service subsequently broadcast a video that showed a senior army officer giving 1,000 Rupee ($10) banknotes to the protesters to pay for their fare home. “This is a gift from us to you,” the major-general is heard telling one bearded militant. The clip went viral. Meanwhile, the High Court in Islamabad asked how the army could act as a mediator between the government and a party the court had already declared a terrorist group.

Islamabad has seen unrest many times before. In 2007, the assassination of the democratic icon Benazir Bhutto led to widespread rioting. The same year, heavily armed militants took over the Red Mosque and fought a pitched battle with security forces. In 2014, supporters of Imran Khan, the cricketer turned politician, laid siege to the city for months to press Khan’s demand that Prime Minister Nawaz Sharif resign. This time around, there was a new pitch to the public’s anger and despair as the state surrendered to mob rule.

“There has hardly been an instance where the state capitulated so humiliatingly to a group of extremists holding the nation’s capital hostage,” said Zahid Hussain, a leading newspaper columnist. Still, no politician spoke up—but for the courageous Bilawal Bhutto, son and young political heir to his mother Benazir’s legacy. “It was demoralizing for my entire generation in the last few days to see the writ of the state erode… to see the rule of law made a mockery of… but now I want to give a message to all the forces that enough is enough and let the country move ahead,” Bhutto said, in a clear jibe at the army.

Moving ahead is difficult, though, when Pakistanis are still at odds over who is holding back the country and allowing extremists to run riot in the capital.

The latest round of crises began in July when the thrice-elected prime minister, Nawaz Sharif, was forced to resign after a controversial Supreme Court ruling disqualified him from holding office because of corruption charges. Sharif’s term was plagued by allegations of corruption against ministers, by incompetence, and by maladministration—all exacerbated by a permanent state of conflict with the army, which has always detested Sharif. Sharif wanted to assert civilian rule, while the army wanted to assert its influence, especially over foreign policy. Only the army, the officer class maintains, can define and protect the national interest. Sharif’s replacement as prime minister, Shahid Khaqan Abbasi, has governed better than Sharif, but it is the ousted Sharif who still runs the Pakistan Muslim League party and calls the political shots.

There has been enough discreet signaling through the media for every Pakistani to know that the military wants Sharif and several other leading politicians to go quietly or face prosecution. But the army miscalculated when they expected Sharif to heed such signals and his popularity to plummet once he left office. That never happened. After holding a series of political rallies, Sharif bounced back, and may still emerge as the major contender in critical elections next summer. As a result, there is endless speculation about what the army’s plan is now. Nobody believes that the military will intervene or take power, but will elections be held on time, or will the judiciary come up with rulings that delay, postpone, or even cancel them?

The Islamabad fiasco brought to the surface another deep concern: the growing sectarianism among the Islamist groups. For two decades, Sunni extremists have been killing Shia Muslims in both Pakistan and Afghanistan. These Sunni militants usually belong to the Wahabbi or Deobandi sects, or offshoots of them, and these include al-Qaeda, the Taliban, and the Islamic State. Their interpretations of Islam are severe, and they reject Shi’ism and Sufism (the mystical side of Islam). The largest Sunni sect in Pakistan is the Barelvis, who have a moderate and more gentle interpretation of Islam partly inspired by Sufism. Until now, they have been largely peaceful and tolerant, and not inclined to religious violence.

That is changing. The Tehreek-e-Labaik are Barelvis who have become extremist in response to what they claim is a lack of respect for the Prophet Muhammad. Barelvi militancy remains a fringe phenomena, but its spread could endanger stability in Punjab, Pakistan’s most populous and prosperous province, where it is a majority belief. It could also lead to future Deobandi-Barelvi rivalries and conflicts.

At the same time, the military is helping resurrect extremist groups that were used by General Zia ul-Haq back in the 1980s, or by General Pervez Musharraf after 2001. Hafiz Saeed, the leader of the extremist anti-India group Lashkar-e-Taiba (LT), was freed from house arrest in Lahore in late November after terrorism charges against him could not be proven. LT carried out the deadly 2008 Mumbai attack that left 166 people dead, including many foreigners, as well as attacks on Indian outposts in Kashmir. The US government imposed a $10 million bounty on Saeed and LT was declared a terrorist group by the United Nations, yet the Lahore court saw fit to release him. In the interim, the group had turned itself into a charitable organization and got permission to form a new political party, the Milli Muslim League, which will take part in elections next year under Saeed’s leadership. Indian officials are apoplectic about this legitimization of Saeed—the White House called the release of Hafiz Saeed a step that “belies Pakistani claims that it will not provide sanctuary for terrorists on its soil.”

Another cause for concern is the revival of the Muttahida Majlis-e-Amal (MMA), an alliance of half a dozen Islamist parliamentary parties that are not necessarily extremist but are certainly pro-Taliban. President Musharraf created the alliance in 2002 to give political cover to retreating Taliban fighters coming over the Afghan border and provide them a sanctuary in Pakistan. The MMA won the 2002 elections in two provinces on the frontier with Afghanistan and it hosted thousands of defeated Taliban arriving from Afghanistan.

None of this would have been possible without the army’s assent. At times, the military claims this is part of the process of reconciling former terrorists with the state, but Pakistan has no national program of deradicalization; there is no mechanism for militants to surrender their arms or seek amnesty. A twenty-point charter to counter extremism that was signed by the military and all the political parties two years ago has largely been abandoned.

The paradox is that even as extremist groups are being rehabilitated, Pakistan faces unrelenting terrorist attacks. On November 29, nine people were killed and thirty-seven injured when at least three terrorists dressed in burkas stormed a student hostel in Peshawar. The attack was claimed by the Pakistani Taliban, which is partly based in Afghanistan and carries out cross-border raids. Pakistan said the attackers had received support from both Indian and Afghan intelligence agencies. A week earlier, Peshawar’s second-highest ranking police officer was killed in a suicide attack. Meanwhile, hundreds of police and civilians have died in Balochistan province, where there is also a separatist insurgency. Pakistan blames India and Afghanistan for what is largely home-grown terrorism.

Despite the ire of the US, NATO, and neighboring states over Pakistan’s refusal to reign in the terrorist groups on its soil, the government in Islamabad either says nothing or parrots the army’s claim that it’s all the Taliban and an Afghan problem. But the US under President Trump is ratcheting up the pressure, including by slashing military aid to Pakistan. On November 30, a US drone strike hit a militant compound inside Pakistan close to the Afghan border, killing three militants. The attack clearly signaled that the US was prepared to carry out more like it, but a more aggressive approach from Washington carries risks; the Pakistani army could respond by shutting down the US supply route for its troops from Karachi port to Afghanistan. A reckless tweet from Trump himself could even prompt an anti-American backlash from a broad cross-section of Islamists—as happened in 1979, when President Zia sat on his hands while a mob burned down the US embassy.

It is not only the US, though, that has been urging Pakistan to stop nurturing the Taliban; Pakistan’s ally China, as well as Iran and the Central Asian republics, have joined the chorus. According to Western diplomats, the Chinese were deeply worried by the recent siege. They have reason to be, since their investment in Pakistan as part of the One Belt, One Road project is worth some $56 billion. Tens of thousands of Chinese technicians are now working in Pakistan; for Beijing, their security is paramount.

Pakistan’s strategic reason for maintaining its support for the Taliban is to prevent Indian involvement in Afghanistan and to assert its influence in any future political settlement there. But there is no sign that Islamabad is taking any initiative of its own, let alone holding peace talks. Instead, it blames Washington for the stasis.

On Pakistan’s eastern border with India, frequent shelling by both armies in the disputed territory of Kashmir reflects increased tension between the two countries. India remains the Pakistani military’s central obsession, and this is the underlying cause of a permanent strife between the army and civilian governments, which would prefer peace and trade with both India and Afghanistan rather than perpetual war.

Even as the Pakistani public is questioning the purpose of the army’s efforts at geopolitical engineering, the parliamentary Islamist parties are being revived to form an electoral bloc that will counter mainstream democratic parties like Sharif’s Pakistan Muslim League and Bilawal Bhutto’s Pakistan Peoples Party—neither of which the “miltablishment” likes. And for the first time, extremist groups like LT are being integrated into the political system, a dangerous and provocative move. Their purpose is also to take votes from the larger parties and help to create a fragmented parliament in which no party has a governing majority—and which the army can more easily control.

Admitting extremist Islamists into the electoral process—groups that have not reconciled with the state and do not subscribe to the constitution or to democracy itself—will pave the way for an even more deadly cycle of violence. If a small fringe group can force the resignation of the justice minister for not being religious enough, the future looks grim. A genuine opposition that could be a counterweight to these machinations—a strong middle class, modern democratic political parties, a vibrant civil society, robust human rights groups, and free media—barely exists. What little there is has been cowed.

Pakistan could have so much going for it—if it dedicated itself to bringing peace to the region and denied militant groups a base. The choices it makes today will determine the future of the region.