Editor's note: Peter Bergen is CNN's national security analyst, a director at the New America Foundation and the author of "Manhunt: The Ten-Year Search for bin Laden -- From 9/11 to Abbottabad."
(CNN) -- Ayman al-Zawahiri, the Egyptian-born leader of al Qaeda, has seen this movie before: An Islamist party does well at the polling booth only to be overthrown by a military coup that then plunges the country into chaos.
This is what happened in Algeria in 1991. Tens of thousands died in the subsequent Algerian civil war that ripped the nation apart during the 1990s.
The lesson that Zawahiri drew from the Algerian war was that participating in democratic elections was strictly for suckers; far better to seize power through violence and then impose Taliban-style sharia law because "the crusaders" and their allies in the Arab world would never allow the emergence of a true Islamist state.
In 1991, the same year that the Algerian civil war began, Zawahiri released his first book, "The Bitter Harvest." The book was a vicious diatribe against the Muslim Brotherhood and other similar Islamist parties for participating in "democracies, elections and parliaments."
Now Zawahiri gets to say "I told you so." Earlier this month Zawahiri posted a 15-minute recording on militant websites. In the recording Zawahiri explained that the military coup that deposed Egypt's elected president, Muslim Brotherhood leader Mohamed Morsy, proved that democracy had failed.
Until recently Zawahiri has been largely overshadowed by his charismatic former boss Osama bin Laden who was killed in a U.S. Navy SEAL raid in Abbottabad, Pakistan, two years ago.
Now the 62-year-old Zawahiri has dramatically stepped into the spotlight as the leader of al Qaeda and its several affiliated groups around the world.
The message traffic during the past weeks between Zawahiri and the commander of al Qaeda's virulent Yemeni affiliate contained code words suggesting some kind of attack was potentially imminent.
Those messages were intercepted by American intelligence and led to the unprecedented closure last week of some two-dozen U.S. embassies and consulates across the Middle East, South Asia and Africa. Germany, France and Britain also closed their embassies in Yemen because of the threat.
Zawahiri's success or failure as the head of al Qaeda will be crucial to how the terror network moves forward as it marks its first 25 years of existence this weekend.
A recent Harvard Kennedy School study of 131 terrorist groups that have gone out of business found that they averaged 14 years of existence.
Al Qaeda has already shown an ability to survive well beyond the life of an average terrorist group. The big question is whether Zawahiri can successfully lead the al Qaeda network so it can thrive in today's chaotic conditions in the Middle East and can last another 25 years.
Zawahiri is a humorless religious fanatic whose forehead is marked with a prominent black scar known in Arabic as a zabiba or "raisin," the result of the many decades he has spent touching his head repeatedly to the floor as he prostrated himself in prayer.
Despite his dour personality, Zawahiri has proven to be more capable as the leader of al Qaeda than many analysts -- including myself — had initially thought.
In the past year Zawahiri has brought two new official affiliates into the al Qaeda network: Somalia's militant al-Shabaab group and Syria's Jabhat al-Nusra, which is widely regarded as the most effective force fighting the Assad regime.
Zawahiri also had no problem transferring already existing al Qaeda affiliates' allegiances from bin Laden to himself. In the three months following bin Laden's death, the leaders of al Qaeda in Iraq, the Yemeni-based al Qaeda in the Arabian Peninsula and the North African al Qaeda in the Islamic Maghreb all pledged their allegiance to Zawahiri as their new overall commander.
Zawahiri has been preparing for this moment all his life, first setting up a jihadist cell in his native Cairo when he was only 15. Like many revolutionaries before him Zawahiri is the son of privilege -- he's from a prominent Egyptian family of ambassadors, lawyers and clerics.
As a teenager Zawahiri believed that the Egyptian government led by Anwar Sadat had abandoned Islam and therefore had to be overthrown. Sadat signed Egypt's ceasefire agreement with Israel in 1979, effectively signing his own death warrant.
In 1981, now trained as a surgeon, Zawahiri was arrested along with hundreds of others for his alleged role in Sadat's assassination and was imprisoned and tortured by Egyptian authorities, an experience that further radicalized him.
Once he was out of jail in the mid-1980s, Zawahiri made his way to Peshawar, Pakistan, where thousands of militant Arabs were then gathering to support the Afghan jihad against the Soviet Union.
It was there in 1986 that Zawahiri first met bin Laden, at that time the shy, monosyllabic son of a Saudi billionaire. For bin Laden the slightly older, cerebral Zawahiri presented an intriguing figure, someone far more experienced politically than himself. For Zawahiri, bin Laden also presented an interesting opportunity: someone who was on his way to becoming a genuine war hero in the jihad against the Soviets and whose deep pockets were well known. They would go on to embark on a marriage of convenience that would have hellish consequences.
During the late 1980s Zawahiri gradually won over bin Laden to his more expansionist view of jihad. Faraj Ismail, an Egyptian journalist who covered the Afghan war against the Soviets, recalls that it was Zawahiri "who got Osama to focus not only on the Afghan jihad, but regime change in the Arab world."
Bin Laden then took the next step, urging Zawahiri to see that the root of the problem was not simply the Arab "near enemy" regimes, but the "far enemy," the United States, which propped up the status quo in the Middle East, a shift in strategy that took place when al Qaeda was based in Sudan in the early 1990s. Bin Laden lectured to his followers there about the necessity of attacking the United States without which the "near enemy" regimes could not survive. Noman Benotman, a Libyan militant who was then close to bin Laden and Zawahiri, recalled that, "Osama influenced Zawahiri with his idea: Forget about the 'near enemy;' the main enemy is the Americans."
When Zawahiri first arrived in Taliban-controlled Afghanistan in 1997, following a six-month spell in a Russian jail, his relations with bin Laden were on a quite different footing than they had been a decade earlier. Bin Laden was now the head of a fast-expanding terrorist organization while Zawahiri was the penniless leader of an obscure Egyptian terrorist group.
It was now bin Laden who took Zawahiri under his wing. And even then bin Laden kept Zawahiri at some distance. It was only in the summer of 2001 that al Qaeda's leader told Zawahiri the details of the coming attacks on New York and Washington, and that was only after Zawahiri's Egyptian Jihad Group had formally merged with al Qaeda in June.
Bin Laden exercised near-total control over al Qaeda, whose members had to swear a religious oath personally to bin Laden, so ensuring blind loyalty to him. Bin Laden's son Omar recalls that the men who worked for al Qaeda had a habit of requesting permission before they spoke with their leader, saying, "Dear prince: May I speak?" Even Zawahiri would ask bin Laden to be permitted to speak.
But now that he is the new boss of al Qaeda, Zawahiri has shown that he no longer feels bound by bin Laden's previous decisions. In 2010 bin Laden instructed the Somali militant group al-Shabaab to keep its association with al Qaeda a secret, fearing that openly linking the two organizations would hinder Shabaab's fundraising efforts. Zawahiri, who had petitioned bin Laden to reconsider his views about the proposed merger between al-Shabaab and al Qaeda, announced formal ties between the two groups in early 2012.
Zawahiri, however, has also had some problems keeping control over the far-flung al Qaeda network. During the spring of 2013 Zawahiri personally intervened to settle a dispute between the Syrian militant group Jabhat al-Nusra and al Qaeda in Iraq. Zawahiri rejected al Qaeda in Iraq's assertion of control over al-Nusra and declared the Syrian group to be under his direction.
However, in June 2013, Abu Bakr al-Baghdadi, the leader of al Qaeda in Iraq (AQI), posted an audio recording online rejecting the order from Zawahiri. This shows that AQI is willing to go public to dismiss the directives of al Qaeda's leader, something that would have been unimaginable when bin Laden was in charge.
After 9/11, Zawahiri acknowledged in his autobiography "Knights Under the Banner of the Prophet" that the most important strategic goal of al Qaeda was to seize control of a state, or part of a state, somewhere in the Muslim world, explaining that, "without achieving this goal our actions will mean nothing."
Indeed, the yardstick by which Zawahiri will be judged as an effective leader of al Qaeda by his fellow militants is the extent to which he can take advantage of the chaotic post-Arab spring conditions in countries such as Egypt, Yemen, Syria, Iraq and Libya to establish safe havens for al Qaeda and its affiliated groups and use those havens to then launch effective attacks against Western targets.
In Pakistan where Zawahiri is generally believed to be hiding and also in Yemen, CIA drone shrikes have eliminated dozens of al Qaeda's leaders over the past three years and establishing a viable safe haven in either country seems quite unlikely. However, a long-term safe haven for Jabhat al-Nusra, al Qaeda's affiliate in Syria, in the heart of the Arab world could create an organization with the intent and capacity to attack the West.
Jabhat al-Nusra ("the Victory Front") has been able to garner considerable support from Syria's Sunni population, because it is the premier fighting force in the campaign to topple Assad, and because it is providing critical services, such as food, hospitals and sharia courts to the embattled population. For the moment, however, Jabhat al-Nusra is entirely focused on overthrowing the Assad regime, a project that may take years to achieve.
Al Qaeda was founded 25 years ago between August 18 and August 20, 1988 during the course of a series of meetings that took place over the course of three days in the sweltering heat of Pakistan's summer in bin Laden's house in the city of Peshawar.
According to the minutes of those meetings, bin Laden presided over discussions involving eight other men who deliberated about how best to establish a new organization that would take holy war to other countries. The minutes noted that "al Qaeda is basically an organized Islamic faction; its goal will be to lift the word of God, to make His religion victorious."
Zawahiri was not at that founding meeting of al Qaeda and for much of the early history of the group he was not a central player in the organization. Today Zawahiri is al Qaeda's overall boss, and he now has the difficult task of turning around an organization whose last successful attacks in the West were the multiple suicide bombings on London's transportation system on July 7, 2005.
If he is to succeed, Zawahiri will have to come up with something more significant than just getting U.S. embassies and consulates to close for a week.
Wherever Zawahiri is right now he is surely watching the unrest unfolding in Egypt with considerable relish and as a real opportunity to exploit. Al Qaeda aligned groups already have footholds in the remote desert regions of Sinai in eastern Egypt and organizations such as Zawahiri's own Jihad Group, which formally merged with al Qaeda in the summer of 2001, have a long history in Egypt.