MITT ROMNEY ENTERED Monday night’s debate trailing President Obama in polls on foreign-policy aptitude and wanting to demonstrate that he could be a sober and competent commander in chief. He began by striking an elevated tone — only to encounter an aggressive and slashing opponent.

Republicans who expected Mr. Romney to renew attacks on Mr. Obama for his handling of a terrorist attack on the U.S. mission in Benghazi, Libya, were disappointed. Instead the GOP candidate chose to address broadly the turmoil across the Middle East, calling for policies to “try to get the Muslim world to reject extremism” and congratulating Mr. Obama on the killing of Osama bin Laden.

Mr. Obama responded with the first of a number of attacks, telling Mr. Romney, “Every time you’ve offered an opinion you’ve been wrong” and assailing “wrong and reckless leadership that is all over the map.” “Attacking me is not an agenda,” Mr. Romney answered.

That set the tone for a debate in which — ironically — the candidates agreed more than disagreed on substance. Mr. Romney joined Mr. Obama in swearing off U.S. military intervention in Syria; they agreed that Egyptian strongman Hosni Mubarak should have been pushed from power. They concurred that the United States would back Israel if it were attacked, and that China’s trade abuses should be checked.

Both candidates promised that U.S. troops would be out of Afghanistan by the end of 2014, and neither mentioned ongoing talks between the U.S. and Afghan governments over a residual force. Mr. Romney backed Mr. Obama’s use of drone strikes in Pakistan and added that he did not fault the administration for the deterioration of U.S.-Pakistani relations.

On Iran, Mr. Obama sought to head off Mr. Romney’s accusations of ineffectiveness in stopping Tehran’s nuclear program by delivering one of the strongest statements he has made about his willingness to use force: “The clock is ticking,” he said. “If they do not meet the demands of the international community, then we are going to take all options necessary to ensure they don’t have a nuclear weapon.” He first denied that bilateral negotiations with Iran were planned after the election, then later thanked Mr. Romney for supporting the possibility of such talks.

But Mr. Obama repeatedly sought to put Mr. Romney on the defensive, at one point accusing the Republican of having wanted to keep troops in Iraq while denying that the White House had supported a stay-on force. In fact, as Mr. Romney pointed out, the administration tried and failed to negotiate an agreement with the Iraqi government on such a force. When Mr. Romney offered a well-worn indictment of Mr. Obama for weakness, saying he had conducted “an apology tour” abroad, Mr. Obama called that “the biggest whopper of the campaign.”

One significant difference emerged, on defense spending, where Mr. Obama repeated his charge that Mr. Romney was proposing $2 trillion in budget increases that the Pentagon had not asked for. Mr. Romney argued that the Navy and Air Force has been allowed to shrink too far; Mr. Obama sarcastically responded that the military also had fewer horses and bayonets than in decades past.

At times, and despite the best efforts of moderator Bob Schieffer to keep the discussion on foreign policy, the candidates veered into domestic policy, from the merits of smaller class sizes in schools to the auto bailout to the familiar but still unanswered question of how Mr. Romney would pay for his planned reduction in tax rates. The domestic discussion broke little ground, but the emergence during the foreign policy debate of what Mr. Obama called the importance of “taking care of business here at home” underscored the degree to which the economy remains the dominant issue of the election.