Dave Espo and Kasie Hunt, Associated Press

Boca Raton, Fla. — President Barack Obama sharply challenged Mitt Romney on foreign policy in their final campaign debate Monday night, saying, “Every time you’ve offered an opinion you’ve been wrong.” The Republican coolly responded, “Attacking me is not an agenda” for dealing with a dangerous world.

Romney took the offensive, too. When Obama said the U.S. and its allies have imposed crippling sanctions on Iran to halt nuclear weapons development, the Republican challenger responded that the U.S. should have done more. He declared repeatedly, “We’re four years closer to a nuclear Iran.”

Despite the debate’s stated focus on foreign affairs, time after time the rivals turned the discussion back to the slowly recovering U.S. economy, which polls show is the No. 1 issue for most voters.

They found little agreement on that, but the president and his rival found accord on at least one international topic with domestic political overtones — Israel’s security — as they sat at close quarters 15 days before the end of an impossibly close election campaign. Each stressed unequivocal support for Israel when asked how he would respond if the Jewish state were attacked by Iran.

“If Israel is attacked, we have their back,” said Romney — moments after Obama vowed, “I will stand with Israel if Israel is attacked.”

Both also said they oppose direct U.S. military involvement in the efforts to topple Syrian President Bashir Assad.

The debate produced none of the finger-pointing and little of the interrupting that marked the presidential rivals’ debate last week, when Obama needed a comeback after a listless performance in their first meeting on Oct. 3.

But there was no mistaking the urgency. The two men frequently sniped at one another even on issues where they agree, and reprised their campaign-long disagreements over the economy, energy, education and other domestic issues despite ground rules that stipulated the debate cover international affairs.

Obama and Romney are locked in a close race in national opinion polls. The final debate behind them, both men intend to embark on a final two-week whirlwind of campaigning. The president is slated to speak in six states during a two-day trip that begins Wednesday and includes a night aboard Air Force One as it flies from Las Vegas to Tampa. Romney intends to visit two or three states a day.

Already 4 million ballots have been cast in early voting in more than two dozen states.

On the Middle East, Romney said that despite early hopes, the ouster of despotic regimes in Egypt, Libya and elsewhere over the past year has resulted in a “rising tide of chaos.” He said the president has failed to come up with a coherent policy to grapple with change sweeping the Middle East, and he added ominously that an al-Qaida-like group has taken over northern Mali.

Anticipating one of Obama’s most frequent campaign assertions, Romney said of the man seated nearby, “I congratulate him on taking out Osama bin Laden and taking on the leadership of al-Qaida. But we can’t kill our way out of this. ... We must have a comprehensive strategy.”

More than a half hour later, Obama returned to the subject, saying that Romney had once said it wasn’t worth moving heaven and earth to catch one man, a reference to the mastermind behind the 9/11 terror attacks.

He said he had decided it was “worth heaven and earth.”

Obama said he had ended the war in Iraq, was on a path to end the U.S. combat role in Afghanistan and has vowed to bring justice to the attackers of the U.S. Consulate in Benghazi last month — an assault that killed the U.S. ambassador to Libya and three other Americans.

He also jabbed at Romney’s having said during the campaign that Russia is the United States’ No. 1 geopolitical foe.

“Governor, when it comes to our foreign policy you seem to want the policies of the 1980s, just like you want to import the social policies of the 1950s and the economic policies in the 1920s,” Obama said.

Obama was snippy after Romney, criticizing the administration’s Pentagon budget, said disapprovingly the U.S. Navy has fewer ships than at any time since the end of World War I.

“I think Governor Romney maybe hasn’t spent enough time looking at how our military works. You mentioned the Navy, for example, that we have fewer ships than we did in 1916. Well, Governor, we also have fewer horses and bayonets because the nature of our military has changed. We have these things called aircraft carriers where planes land on them.”

Romney offered unusual praise for Obama’s war efforts in Afghanistan, declaring the 2010 surge of 33,000 U.S. troops a success and asserting that efforts to train Afghan security forces are on track to enable the U.S. and its allies to put the Afghans fully in charge of security by the end of 2014. He said that U.S. forces should complete their withdrawal on that schedule; previously he has criticized the setting of a specific withdrawal date.

Barring a last-minute change in strategy by one campaign or the other, Obama appears on course to win states and the District of Columbia that account for 237 of the 270 electoral votes needed for victory. The same is true for Romney in states with 191 electoral votes.

Obama’s campaign launched a television ad in Florida that said the president ended the war in Iraq and has a plan to do the same in Afghanistan, accusing Romney of opposing him on both. It was not clear how often the ad would air, given the fall’s overall focus on the economy.

Vice President Joe Biden, campaigning in Canton, Ohio, emphasized differences between the two candidates on the war in Afghanistan.

“We will leave Afghanistan in 2014, period. They say it depends,” he said. “Ladies and gentlemen, like everything with them, it depends. It depends on what day you find these guys.”

Romney’s running mate, Wisconsin Rep. Paul Ryan, was in Colorado. “We are in the midst of deciding the kind of country we’re going to be, the kind of people we’re going to be, for a generation,” he said.

Whatever the outcome of the final face-to-face confrontation, the debates have left an imprint on the race. Romney was widely judged the winner of the first debate over a listless president on Oct. 3, and he has risen in polls in the days since. Obama was much more energetic in the second.

Monday night marked the third time in less than a week that the president and his challenger shared a stage, following the feisty 90-minute town-hall-style meeting last Tuesday on Long Island and a white-tie charity dinner two night later where gracious compliments flowed and barbs dipped in humor flew.

At the Al Smith charity dinner, Obama previewed his all-purpose fallback to criticism on international affairs.

“Spoiler alert: We got bin Laden,” he said, a reminder of the signature foreign policy triumph of his term, the death at the hand of U.S. special operations forces of the mastermind behind the terror attacks on the United States more than a decade ago.

The president and his challenger agreed long ago to devote one of their three debates to foreign policy, even though opinion polls show voters care most about economic concerns.

Growth has been slow and unemployment high across Obama’s tenure in the White House. Romney, a wealthy former businessman, cites his experience as evidence he will put in place policies that can revive the economy.

In recent weeks, the former Massachusetts governor has stepped up his criticism of the president’s handling of international matters, although his campaign hasn’t spent any of its television advertising budget on commercials on the subject.

In a speech earlier this month, Romney accused the president of an absence of strong leadership in the Middle East, where popular revolutions have swept away autocratic regimes in Egypt and elsewhere in the past two years. He has also accused Obama of failing to support Israel strongly enough, of failing to make it clear that Iran will not be allowed to develop a nuclear weapon and of backing cuts in the defense budget that would harm military readiness.

Yet Romney has stumbled several times in attempting to establish his own credentials.

He offended the British when he traveled to England this summer and made comments viewed as critical of their preparation for the Olympic Games.

Democrats pounced when he failed to mention the U.S. troops in Afghanistan or Iraq during his acceptance speech at the Republican National Convention in late August, and officials in both parties were critical of his comments about the attack in Benghazi while the facts were unknown.