Media playback is unsupported on your device Media caption Obama and Romney clashed on the debate floor over energy policy

A more aggressive Barack Obama buried the memory of a poor first showing as he and Republican presidential challenger Mitt Romney clashed in the second presidential debate in New York.

Mr Obama, perceived to have lost their first encounter, came out swinging on the economy, tax and foreign policy.

Snap polls after the debate suggested Mr Obama "won" the contest, although by a narrower margin than his opponent was perceived to have won the first.

But analysts say the race stays tight.

BBC North America editor Mark Mardell says Mr Obama has stopped the panic in his camp.

Back on the trail

What Team Obama would have dreaded was anything that contributed to a narrative of decline and defeat for the Democrat as he bids for a second term, our correspondent adds.

A CBS poll of undecided voters who watched the debate gave it to Mr Obama, 37% to 30% with 33% calling the debate a tie.

President Obama redeemed himself. He did what he had to, and perhaps some more

Meanwhile, a CNN poll of registered voters who watched - not just undecideds - gave the debate to Mr Obama 46%-39%.

The morning after the debate, the candidates were back on the campaign trail, targeting their messages at voters in swing states.

Mr Romney was scheduled to spend the day in the state of Virginia and Mr Obama in Iowa, while their running mates - Congressman Paul Ryan and Vice-President Joe Biden - were bound for Ohio and Colorado respectively.

In the town hall-style forum at Hofstra University on Long Island, the candidates roamed the stage, circling, interrupting and at times heckling one another as they took questions from an audience of 80 undecided voters.

The moderator, CNN's Candy Crowley, often had to intervene to keep order.

The 11 questions from the voters present ranged from gun control to Libya to immigration, but the main focus was on the economy.

The most dramatic clash came over foreign policy, and the attack last month on the US consulate in Benghazi, Libya, which left the US ambassador and three other Americans dead.

Mr Romney sought to portray the attack as evidence of the Obama administration's failing foreign policy and he suggested Mr Obama had dithered over admitting a terrorist attack had occurred.

Mr Obama shot back that he had said so the day after the attack, in an appearance at the White House.

The Republican challenged this, saying: "It took the president 14 days before he called the attack in Benghazi an act of terror."

'Road to Greece'

When Ms Crowley confirmed that Mr Obama had indeed called the attack an "act of terror" the day after the attack, the president told the moderator: "Say that a little louder, Candy."

The president also accused Mr Romney of using the Libyan events for political purposes. "While we were still dealing with our diplomats being threatened, Governor Romney put out a press release, trying to make political points, and that's not how a commander-in-chief operates," he said.

Mr Obama accused Mr Romney of inconsistency, and contrasted his own bailout of the US car industry with the Republican's position that car-makers should have been allowed to go bankrupt.

In turn, Mr Romney blamed the president for unemployment of 20 million and bloated federal deficits.

America, he insisted, could not afford another four years with Mr Obama at the helm, warning that Mr Obama's policies would ultimately prove as disastrous as the euro debt crisis.

"We've gone from $10tn of national debt to $16tn of national debt," he said.

"If the president were re-elected, we'd go to almost $20tn of national debt. This puts us on a road to Greece."

Mr Obama said voters had heard no specifics on Mr Romney's "sketchy" economic plan apart from eliminating Sesame Street's Big Bird and cutting funding for Planned Parenthood, a family planning organisation Republicans say promotes abortion.

'Binders full of women'

But Mr Romney insisted his budget would add up, and cited his experience in balancing budgets in business while running the 2002 Olympics and as governor of Massachusetts.

Media playback is unsupported on your device Media caption Candidates exchange barbs on jobs plans

Both campaigns released videos building on themes from Tuesday's debate.

A video from the Republicans, called Holding President Obama Accountable, weaves together highlights from Mr Romney's comments during the debate.

An ad from the Obama campaign focuses on Mr Romney's debate remark about "binders full of women".

While answering a question about equality in the workplace, Mr Romney said that he had sought out female employees as governor of Massachusetts.

"I went to a number of women's groups and said, 'Can you help us find folks?' and they brought us whole binders full of women," Mr Romney said.

The remark quickly went viral online, prompting a deluge of commentary on Twitter and other social media.

BBC North America editor Mark Mardell says that the body language of the debate was fascinating - a showdown between two highly successful men who are used to winning.

At one point, they almost squared up to each other, uncomfortably close, invading each other's personal space, hands raised in a gesture that says "stop - I'm talking", he says.

The pair meet for their final debate in Florida on 22 October, with the election following on 6 November.