WASHINGTON — On Wednesday evening, moments after finishing a summit meeting with African leaders at the State Department, the chairman of the Joint Chiefs of Staff delivered a stark message to President Obama as they rode back to the White House in Mr. Obama’s limousine.

The Kurdish capital, Erbil, once an island of pro-American tranquillity, was in the path of rampaging Sunni militants, the chairman, Gen. Martin E. Dempsey, told the president. And to the west, the militants had trapped thousands of members of Iraqi minority groups on a barren mountaintop, with dwindling supplies, raising concerns about a potential genocide.

With American diplomats and business people in Erbil suddenly at risk, at the American Consulate and elsewhere, Mr. Obama began a series of intensive deliberations that resulted, only a day later, in his authorizing airstrikes on the militants, as well as humanitarian airdrops of food and water to the besieged Iraqis.

Looming over that discussion, and the decision to return the United States to a war Mr. Obama had built his political career disparaging, was the specter of an earlier tragedy: the September 2012 attack on the diplomatic mission in Benghazi, Libya, which killed four Americans, including Ambassador J. Christopher Stevens, and has become a potent symbol of weakness for critics of the president.