These tense moments punctuated a fierce back-and-forth exchange between the candidates over the responsibilities of the commander in chief, and Mr. Obama’s record of dealing with the turmoil of the Arab Spring. Mr. Romney said the Libyan attack was part of a broader Middle East policy that was “unraveling right before our eyes.”

The president accepted responsibility for the security lapses that led to the attack, saying the four Americans who were killed “are my folks.” He pledged a thorough investigation and said he would have those responsible for it hunted down. But he swiftly turned the tables on Mr. Romney, saying that his campaign had issued a news release criticizing the administration’s handling of the attack before the United States knew the fate of its personnel.

“The suggestion that anybody in my team, whether the secretary of state, our U.N. ambassador, anybody on my team would play politics and mislead, when we lost four of our own, Governor, is offensive,” Mr. Obama said, glaring at his opponent. “That’s not what we do, that’s not what I do as president, that’s not what I do as commander in chief.”

China also figured prominently in a debate for the first time, with Mr. Romney and Mr. Obama trading charges over who would be tougher in cracking down on China’s trade practices. Mr. Romney said the president had missed regular chances to label China a currency manipulator for artificially lowering the value of its currency, making its exports cheaper.