BOCA RATON, Florida — A feisty President Barack Obama ridiculed Mitt Romney as "all over the map" on foreign policy, accusing him of telling untruths and backing "wrong" policies in their fiercely fought final debate.

Obama and his Republican foe clashed on Iran's nuclear program, the Arab Spring, Libya and Syria, diverting at times to the domestic economy, as they sought to break the deadlock in the White House race two weeks from election day.

The president, playing on his poll ratings as a strong leader, said that Romney had changed his positions on foreign policy over and over again and warned that he lacked the consistency needed of a commander-in-chief.

"On a whole range of issues, whether it is in the Middle East, Afghanistan, whether it is in Iraq, whether it is in Iran, you have been all over the map," Obama said in the foreign policy-themed debate in Florida.

And he openly mocked Romney's claims that that he had run down the armed forces to levels not seen since early in the 20th Century.

"You mentioned the navy, for example, and 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's changed," he said to laughter from the audience.

"We have these things called aircraft carriers where planes land on them. We have these ships that go underwater, nuclear submarines.

"So the question is not a game of Battleship where we're counting ships. It's, what are our capabilities?"

Romney launched a sweeping critique of Obama's policies on the Arab Spring, Syria and Iran, but was careful to come across as moderate, moving away from more conservative positions as he took a commander-in-chief test.

Often, Romney appeared to differ with the president more on tone than substance, as the rivals vied for the votes of remaining undecided voters in crucial swing states.

Romney, a former Massachusetts governor congratulated Obama for "taking out" Osama bin Laden, but warned Islamic extremism was rampant in post-Arab Spring societies, and cautioned "we can't kill our way out of this mess."

Romney also called on Obama to do more to end violence in Syria and demanded tightened sanctions on Iran over its nuclear program.

"I thought they saw weakness where they had been expected to find American strength," Romney said of leaders in Tehran, accusing the president of making "apology tours" abroad.

The president hit back, complaining "nothing Governor Romney said is true," calling his Iran charge the "biggest whopper" of the campaign.

Obama also launched a scathing attack on Romney's foreign tour as a candidate earlier this year, saying when he had been running for the White House he visited US troops and Israel to reflect on the Holocaust.

"I didn't take donors," Obama charged, noting the fact that Romney carried out a political fundraisers with wealthy Jewish donors in Israel.

The president looked puzzled, bemused and sometimes incredulous with Romney's savage critique of his diplomacy, as seen on a split screen carried by television networks screening the debate.

"I know you haven't been in a position to actually execute foreign policy, but every time you've offered an opinion, you've been wrong," Obama told his opponent, a former Massachusetts governor.

The president, who withdrew troops from Iraq, pointed to Romney's past statements in support of keeping a US military presence in the country that was invaded in 2003 under former Republican president George W. Bush.

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

Romney offered a dismal assessment of the president's strategy, pointing to bloodshed in Syria and in Libya -- where four Americans including the US ambassador were killed last month -- and twice mentioning Al-Qaeda gains in Mali.

Obama called the violence in Syria "heartbreaking."

The rivals are neck-and-neck in national polls after Romney surged following his first debate win in early October and started chipping away at Obama's foundation in the swing states that will decide the election.

Foreign policy is unlikely to decide who wins on November 6, with the sluggish economy driving the election, but Romney is under pressure to show basic competence following a string of blunders.

New polls released Monday had the race a cliffhanger with two weeks to go.

CBS News and ABC News had Obama up by two and one points in the national race, but a Politico/GWU/Battleground poll showed Romney leading by two points.

While national polls offer a snapshot of momentum in the race, the nine or so states that could swing to either side will define the outcome.

Obama retains several pathways to the 270 electoral votes needed to win on November 6, but Romney has chiseled away at his advantage with signs that Florida and North Carolina are slipping towards the Republican.

Romney won the first debate after a lethargic performance from Obama, but the president's feisty showing on Long Island, New York last week made the third debate as a tie-breaker of sorts.