Frederic M. Wehrey is a senior associate in the Middle East Program at the Carnegie Endowment for International Peace and co-editor of “Perilous Desert: Insecurity in the Sahara.”

While many Americans have been riveted by recent congressional testimony and debate about the Sept. 11, 2012, attack on the U.S. diplomatic outpost in Benghazi, this country has been caught in its own drama.

In recent days, amid Libya’s worst political crisis since the 2011 revolution that toppled Moammar Gaddafi, the United States and other Western governments have evacuated their diplomatic staff. A Marine quick-response team and a Special Operations unit were placed on alert. But this is precisely the time for greater engagement, not retreat, not only with Libya’s beleaguered government but also with its increasingly assertive civil society. Engagement is crucial for securing Libya’s future and preventing its weakness from inflaming conflicts in North Africa and the Middle East.

Over the past two weeks, armed militias have laid siege to government ministries in the capital, Tripoli, demanding that the elected parliament pass a controversial law that would bar a range of officials who served in the Gaddafi regime from government employment. Effectively held at gunpoint, legislators passed the bill last week, but the siege continued until this past weekend, with militias encamped at the ministries and demanding the ouster of Prime Minister Ali Zeidan and his cabinet. “A slow-motion coup” was how one Libyan described the standoff to me. Meanwhile, an explosion Monday in front of a Benghazi hospital killed three, sparking outrage across Libya at the ongoing security vacuum in the city.

In nearly every crisis in Libya since 2011, civil society has helped pull the country back from the brink. Last Friday, thousands of Libyans marched toward the besieged Foreign Ministry to confront the armed militias. Those I spoke with said they were marching for the principles of due process and democracy. True, many disagreed with the government, its corruption and its inefficiency. But their signs and banners bore witness to the idea that changes in government should come through legal, peaceful means, not by armed intimidation. By late Friday evening, the militias had fled; by Saturday night, the ministries had returned to business.

In the wake of the violence in Benghazi, there have been similar displays of outrage, with citizens demanding that the government replace the militia groups in the city with formal police and army troops. It was a stunning display of people power, reminiscent of the demonstrations by civilians who stormed the militia headquarters in Benghazi in September after the death of U.S. Ambassador Chris Stevens and three of his colleagues. On Thursday, the government heeded these calls, sending in special forces to shut down a notorious arms market in the city and deploying troops along its major roads.

But civil society alone cannot succeed against the enormous challenges facing this country. Most crucially, the “political isolation law” is polarizing society and impeding progress on many fronts. At one level, the law reflects deep-rooted questions about whether the countless bureaucrats and technocrats who served in Gaddafi’s machine — even if they personally committed no crimes — should be allowed to remain in their posts. On another level, it is a disturbing political game: a bid by Islamist elements and politicians and the powerful city-state of Misurata to force the hand of the elected government. The law’s passage by force set a dangerous template for armed intimidation that other disgruntled factions could try to emulate.

In the midst of this gridlock, Libya’s porous southern borders have become thoroughfares for smugglers, illegal migrants and jihadists. Arms from Libya are fueling conflicts in Mali, Gaza and Syria. The regular army and police remain hollow shells, while the various militia coalitions, although nominally under government control, are the real arbiters of power.

For many Libyans, there is gnawing disenchantment with the pace of progress and even hints of nostalgia for the old order. Added to this, many are disheartened by the retreat of Western governments and companies. While an ultimate resolution of the political crisis rests with decision-makers and civil society, outsiders can do much more. A potential window is closing. Now is the time for greater assistance from the United States and Libya’s Western allies.

Read more from PostOpinions:

Charles Dunne, Stephen McInerney and Karim Mezran: Libya needs U.S. help with its transition to democracy

The Post’s View: John Kerry’s efforts in the Middle East could lay the groundwork for success

Ed Rogers: The Insiders: Enough Benghazi already