To visit Benghazi these days is to enter a stricken city, a city at war with itself. The site of the first protests in 2011, the courthouse and nearby buildings, are a no-go zone, a shambles of twisted iron and spilled concrete pocked by heavy caliber rounds. Those who gathered there in the heady days of the revolution are now on opposite sides of a conflict that has torn apart families, killed or wounded thousands, and displaced many more. All the while, the Islamic State moved in. Its black banners now flutter from ruined rooftops; its fighters hurl taunts in Tunisian-accented Arabic and blare recorded sermons across the front lines.

How did this happen?

The ultimate blame must lay with Muammar Gaddafi himself, who bequeathed Libyans a country without a state. Leaders of the new Libya found it hard to break free from the pull of an exploitative, hyper-personalized reign that pitted communities against one another and atrophied institutions, the sinews of governance. Of course Libyan actors carry responsibility; incompetence, petty vendettas, and an unabashed lust for power all played a role. So too did ambivalence and meddling by outside powers. A confluence of fateful missteps during and after the revolution set the country on downward spiral that will probably take years to reverse.

The revolutionaries were divided among themselves from the start. It was always a highly localized insurrection; neighborhoods and towns rose up bereft of unifying leadership or a shared vision. The fault lines were many: between communities enriched by Gaddafi’s rule and those marginalized by it; between Libyans who returned after decades abroad and those who stayed; between technocrats who had accommodated the regime and worked to reform it, and Islamists who languished in its prisons; between defected army generals and younger civilian fighters; between women who challenged the old patriarchy and conservatives who sought to enforce it.

Outside military support sharpened the fissures: Factional militias jostled for weapons shipments and training from competing patrons. The revolution’s fragile governing coalition, the National Transitional Council, proved powerless to bridge these divides and at any rate was overtaken by local forces and events on the ground. Whatever plans it had developed for the post-Gaddafi period, with outside help, dissolved on first contact. The fall of the capital proceeded pell-mell. Advancing militias seized airports, ports, armories and ministries as spoils to be converted into political power later on. Still, in those first several months after liberation, it was possible to be guardedly optimistic.

The United States returned to Libya, but with a narrow mandate and an overly optimistic assessment of the country’s transition needs. “There was this sense that Libya had a lot going for it, that given its oil wealth and small population, this would not be a strictly bottom-up affair,” one former White House official told me. Haunted by Iraq and Afghanistan, the Obama administration was desperate to avoid a nation-building imbroglio and a militarization of America’s presence in Tripoli. The Libyans themselves feared a creeping occupation and were highly divided about how much Western assistance they wanted. Even the nominal troops at the American Embassy for security required calming assurances to Libyan leaders.

Much of the U.S. effort was focused on bolstering civil society, education and a free media, what one diplomat termed “nation-building by proxy.” No doubt it was inspiring to watch the blossoming of voluntary associations, clubs, charities, and media outlets, unfettered by government control. And the United States and others did their best to nourish these groups. Yet the impact of aid was destined to be limited, given the absence for so long of meaningful people-to-people contacts between the United States and Libya under Gaddafi. Moreover, many of the Libyan civil societies, whose dual-citizen leaders gathered in marble hotel foyers eager for outside support, rarely penetrated beyond Tripoli or Benghazi. But perhaps most damningly, the absence of early Western assistance on the security front left the activists vulnerable to violence by militias and extremists.

Using elections as a marker of success

The United States ceded much responsibility to the Europeans and United Nations. But without a stabilization force, the United Nations mission was, by its own admission, ill equipped to handle the challenges of rebuilding the hollowed-out security sector and especially dismantling the well-armed militias. It focused instead on the preparing the country to vote for a national legislative assembly. For the country’s transitional leadership and for the United States, so much was tied to those elections; too much, in retrospect. “We got distracted by the elections as a success marker,” an American development worker at the time told me. “Rushing the elections was a grave mistake,” admitted one former senior UN official in Libya.

And rushed they were. The transitional leadership decreed that elections would take place 240 days after liberation — for a country that had not held national voting in more than half a century that is light speed. Some veteran scholars of democratic transitions warned at the time, almost prophetically, that holding elections in Libya so soon after conflict would lead to a relapse of civil war. When elections did happen, on July 7, 2012, they took place amid acts of armed coercion by federalists, tribal fighting in towns in the west and south and rising extremist violence in the east.

Still, turnout was relatively high and Western observers deemed the voting fair and transparent. Few within the NTC or in the West were naive enough to think that elections would themselves resolve the country’s yawning divides. But the great hope was that the country’s elected government would have stronger legitimacy to tackle growing lawlessness and insecurity. In fact, the new legislature, the General National Congress, entrenched and solidified factionalism.

Growing militia power

The contest for security institutions — for the monopoly of control on force — proved Libya’s undoing. The NTC had at various times tried to dissolve the militias. At the same time, bereft of the ability to project its authority it began subsidizing militias, placing them on the nominal control of the ministries of interior and defense. But these ministries were themselves captured by competing political factions. The result was a swelling of militias — beyond the number that had fought in the revolution — and the formation of a localized, highly divided and hybrid-security sector that existed in parallel to the decrepit army and police.

The new elected government were unable to resolve the most pressing question of whether to preserve and reform the remnants of the old military or undertake a wholesale remaking of the security structure that privileged younger revolutionaries. Even worse, figures within the GNC developed a symbiotic relationship with outside militias, who began threatening elected authorities over passage of a lustration law, kidnapped the prime minister, and seized oil facilities. Mindful that government could not even protect its own buildings or personnel, the United States, Britain, Turkey and Italy planned for the overseas training of a purportedly neutral army, the so-called general purpose force. But it was too little too late. Those trainees that returned found there was no military structure to join; they were put on indefinite leave or melted back into the militias.

Egypt’s shadow over Libya

Another major shock to Libya occurred at the regional level. The rise of now President Abdel Fattah al-Sissi in neighboring Egypt and the subsequent crackdown on the Muslim Brotherhood cast a long shadow over Libya. It sharpened a conspiratorial paranoia that had taken root in Libyan politics. This polarization was already well underway, fueled in part by the spread of highly partisan media funded by influential Libyans abroad. But after the crackdown in Cairo one started hearing the term “deep state” muttered fearfully and with greater frequency within Libya’s Islamist and revolutionary circles. For their part, the ex-technocrats and officers, eastern tribes, federalists and some liberals started looking approvingly at Sissi as an exemplar for restoring order and, less nobly, excluding their opponents from power.

Nowhere was the “Sissi effect” felt more acutely than in Benghazi. Here, a wave of assassinations against military officers, police, judges and activiststerrorized the populace. Buoyed by this groundswell, Gen. Khalifa Hifter, a former Gaddafi-era military officer, launched Operation Dignity in May 2014, with the stated goal of evicting Islamist militias from Benghazi and restoring security. Less obvious was Hifter’s desire to restore the primacy of the old officer corps within the security sector over the younger revolutionaries and Islamists. He forged alliances with a wide array of groups, included western Zintani militias with whom he had clashed in late 2011. Many of them eyed him warily but saw a utility in joining his campaign to undermine their local rivals.

Hifter and his allies made a number of threats against the GNC and vowed to bring their military forces to Tripoli. These threats, along with losses in elections for the follow-on legislature to the GNC, spurred a counter-movement to Dignity, the so-called Dawn movement, which began with a military attack by Misratan, Islamist and western militias on Tripoli’s airport to evict the Hifter-allied Zintanis.

Dueling factions backed by regional powers

What followed was the effective division of the country into two rival governments: one in the east, based in Tobruk and Bayda and allied with Hifter, and one in Tripoli, backed by a constellation of Misratan, Islamist and western militias. Regional military intervention sharpened the conflict. The UAE and Egypt backed General Hifter forces with airstrikes, weapons and special operations; Qatar, Turkey and Sudan backed elements of the Dawn coalition.

Enter the Islamic State

The ensuing war has brought Libya untold humanitarian and financial ruin, spreading to the central oil fields and the southern periphery. In Benghazi, the struggle created new space for extremists by making allies of disparate Islamist militias whom Hifter had lumped together. Worse, the fighting has taken on a vicious, communal quality between families and neighborhoods. Forced displacement, torture and summary executions are widespread on both sides.

Amid personal and tribal divisions, the Dignity campaign has stalled. For their part, power brokers in Misrata and Tripoli continued to play a dangerous game of shipping weapons to Benghazi’s battle lines, where the distinctions between their favored militias and more radical groups like Ansar al-Sharia and, increasingly, the Islamic State, has blurred.

The Islamic State has seized on the vacuum to implant itself in Sirte, in surrounding towns in the so-called oil crescent, some neighborhoods in Benghazi, the environs of Derna, and Sabratha and Tripoli in the west. Fortified by an influx of foreign fighters and defectors from Ansar al-Sharia, it seems determined to disrupt the formation of the new government by cutting off oil revenue and attacking its fledgling security forces. The Dignity and Dawn fighting has enabled its spread; each side seems more focused on the other, and each has cynically accused the other of collusion with the Islamic State.

A unity government under stress

Under great pressure from the West and their respective regional backers, representatives from the two sides recently signed a U.N.-brokered agreement to form a unity government. But the new government faces enormous political and security challenges in taking office in Tripoli and exerting its authority. A key stumbling block remains control over Libya’s military and specifically the continued role of Hifter as commander-in-chief of the Libyan National Army, which Dawn factions fiercely oppose. Another is the fragmentation and devolution of power within the Dawn and Dignity camps, so much so that they exist in name only. This not only opens door for spoilers and rejectionists, it complicates U.S. and other Western efforts to channel military aid in the fight against the Islamic State through a cohesive chain of command. It simply does not exist.

But perhaps most troubling has been the spread of a profound disenchantment with the revolution’s early promise, a despair that extends not just to democracy, but to politics itself. Along with the country’s ruptured social fabric, it is an affliction that will be difficult to remedy.

This article originally appeared at the Washington Post