The U.S. embassy in Singapore.

Washington faced a 3 AM moment a few months ago when it learned about the assault on the U.S. consulate in Benghazi and the murder of Ambassador Christopher Stevens and the other Americans who were with him. This was not the first one, of course, nor will it be the last. I was introduced to the idea of the 3 AM moment in 2001, when I was undergoing the two-week training session on embassy leadership in preparation for becoming the U.S. ambassador to Singapore. One of the exercises involved something of a trick question: What is the most important article of clothing for an ambassador? Is it white tails, for state weddings and funerals? Perhaps black tails, for formal dances and banquets? Maybe even an ordinary business suit for ministry calls? In fact, the answer was pajamas and a bathrobe. Simply put, most every ambassador eventually finds himself or herself managing a crisis from the ambassador's residence at 3 AM. Best to have some good PJs and a respectable robe on hand.

The U.S. embassy in Singapore might not have seemed a likely post for crisis management, but when the United States and its allies went into Afghanistan after 9/11, a majority of the U.S. forces that went to war were routed there via Singapore. There is no hard evidence that al Qaeda knew how important the country was to the U.S. mission, but we know that in response to the allied invasion of Afghanistan, al Qaeda decided to inflict a massive attack on Singapore. It was to be their first post-9/11 strike.

In December 2001, just four months after I arrived at my post, the government of Singapore alerted me that al Qaeda and its affiliate Jemaah Islamiyah (JI) planned to target the U.S. embassy with a car bomb. According to the Singapore Internal Security Department (ISD), the group had procured four tons of ammonia nitrate to make the bomb, as well as fuses and a truck. The plot was perhaps days away from being operational. All that was left was for JI to import suicide drivers. British special forces quickly confirmed what the ISD told us. They had uncovered a chilling video in an al Qaeda safe house in Afghanistan. In it, jihadis exchanged light-hearted banter, discussed security barriers around the U.S. embassy, and debated a plan to kill us: first, a truck bomb would detonate at our security gates. That would allow the second and larger truck bomb to drive through them and destroy the embassy.

I remembered from my training that al Qaeda used a similar two-bomb approach in 1998, when it attacked the U.S. embassies in Kenya and Tanzania. In both cases, the first hit drew people to the windows, and the second killed them with flying shards of glass. More than 200 people died, and the FBI added a new name to its list of the top ten fugitives: Osama bin Laden.

Three years later, the United States was contending with more of bin Laden's handiwork, this time in Singapore. The ISD assured me that Singapore was preparing to thwart the attack. Under orders to "act normal," I was cheese in a mousetrap. I could not leave my post, change my routine, or let even one word slip about al Qaeda's plans -- or about the efforts to thwart it. The security team could not even notify the entire embassy about the situation, due to the "no double standard" rule. This rule, which the State Department imposed after the 1988 bombing of Pan Am flight 103, mandated that any terrorist threat that the State Department shared with the community of U.S. officials also had to be shared with the American public. To avoid violating that rule and tipping off enemies, I could discuss the threat only with the team responsible for countering it.

While acting as normal as possible (But how long does it normally take to shave in the morning? How long to exercise in the gym -- or should one be at the gym at all?), the security team and I tried to prepare for the day the blast would come. We reviewed perimeter security architecture, rules of engagement, fire control mechanisms, and so forth. I went to the shooting range with the embassy marine detachment to make sure that my pistol qualifications were up-to-date. More important, I tried to spend as much time as possible with the marines, to make sure they could recognize my voice if everything went dark. Meanwhile, we kept on hand individual breathing apparatuses to get us through smoke or a "white powder" attack, an attack with anthrax or another toxin. We also had individual autoinjectors with atropine to counter nerve agents. After a number of consultations with the State Department, all parties concluded that there were really no other preparations to make.

At that point, it was up to our Singaporean hosts to disrupt the plot. The ISD focused on technical and physical surveillance of the terrorists to make sure that they had uncovered the entire cell, its leadership, its financial network, and the parties with whom it communicated. One woman was observed sketching the house of the defense minister. She turned out to be an innocent architecture student completing a homework assignment. Another man would appear at the bus stop across the street from the embassy at approximately the same time every day, but he never boarded a bus. He would loiter at the stop for a few minutes and then walk off the way he came. For several days in a row, he managed to elude the authorities. When they did nab him, he turned out to be an ordinary citizen who was under doctor's orders to walk one kilometer a day. Our bus stop was exactly half a kilometer from his apartment.

The state of limbo went on for about ten days, when, to my enormous relief, the ISD conducted a nationwide "roll-up" of the terrorist cells. On December 9, it arrested 15 terrorists. The following August, it picked up 21 more.

Unfortunately, the good news in Singapore soon turned into bad news some months later in Bali. As JI later revealed, it had concluded that Singapore was a hard target and that it needed to find a softer one. On October 12, 2002, the group detonated a series of bombs at restaurants and nightclubs on Bali frequented by Western tourists. Among the 202 dead were seven Americans. The blasts, like those in Kenya and Tanzania, constituted one of the dozen terrorist attacks in history that have ever killed more than 200 people.

Just over ten years later, militants followed their old embassy attack playbook -- this time with lethal success. The Benghazi assault is still under investigation, but it is clear that a well-planned al Qaeda-led assault quickly penetrated the consulate perimeter and overwhelmed the defenders, resulting in the deaths of the U.S. ambassador and three others. There is no good reason that Chris Stevens is dead today and I am alive. As the attacks in Kenya, Tanzania, Bali, and now Libya remind us, although we depict terrorists as fanatics, they are also methodical and calculating. Counterterrorism requires no less in the way of methodology and calculation.

My experience in Singapore offers other important lessons, as well: First, close coordination with the host government is essential. Even the best-protected diplomatic facility cannot defend against a sustained assault. Certainly, I had the advantage of a highly competent host government and a modern embassy facility, and the government of Singapore deserves high praise for its professionalism and responsiveness. It took its duties to the Americans stationed in the country seriously -- and it had the people and the systems in place to make the difference.

Second, good intelligence saves lives. Our ability to get raw information from the British and from the ISD, as well through our own intelligence gathering capabilities, helped us predict what al Qaeda would do next and devise mechanisms to counter. It is, as yet, unclear what intelligence the U.S. facility in Libya had.

Third, popularity should not be confused with security. I made it a point to signal to the general public that the Americans were prepared to stand our ground, but that we would do so in a low-key fashion -- we love having visitors, but please call ahead. In Libya, some of the more poignant responses to the murder of Stevens in Benghazi were comments about how popular he was in Libya -- how he had worked with insurgent groups to help overthrow the Muammar al-Qaddafi regime. That fact is important, but is not directly related to his security. Indirectly it probably undermined his security. Paradoxically, the enormous strengths that Stevens brought to his assignment -- his rapport with the Libyan people, his personal courage, and his revolutionary credentials -- made him a trophy target.

Fourth, it is important to work with what you have. The U.S. government has enormous resources, but access to them is constrained by bureaucracy and wartime exigencies. An embassy staffer in Singapore once commented that the U.S. government would spend more on a person's funeral than it would on his or her protection. That statement is not literally true, of course, but it does highlight the fact that the U.S. government tends to act most rapidly after a crisis has occurred.

Fifth, management, training, morale, and communications all matter. There is a reason ambassadors should conduct entrance interviews with every new embassy hire. It helps establish a pattern of communication and responsibility from the start. Similarly, there is a reason for ambassadors to attend the marines' Friday barbecues. They are town hall meetings, which allow any member of the embassy team to raise any topic they choose. I went to the pistol range not only because I believed I might soon be firing rounds at terrorists, but also because it was an effective way of communicating with the marines and showing leadership.

Sixth, simply foiling attacks will not defeat al Qaeda. To borrow from a hymn, it is not enough to unleash a swift sword; you also have to also trample out the vintage where the grapes of wrath are stored. In the past decade, the United States has worked closely with Indonesia to help it strengthen its democratic structures, shore up its economy, and build up its counterterrorist capability, but it could take a longer commitment to help Libya get on the right path given its smaller middle class and its recent emergence from repression.

An American friend commented to me when it was all over that I was just in the wrong place at the wrong time. My feeling was the opposite: I was in the right place at the right time. U.S. ambassadors are trained for the 3 AM call -- and it's more than having a good robe. I got the chance to see the mission through, help foil a terrorist plot, and strengthen U.S. ties with a good partner in the process. Perhaps the most notable element of this story is that my experience isn't unusual -- it is what ambassadors do.