A fired-up President Barack Obama persistently attacked Republican challenger Mitt Romney in a critical debate, offering a striking contrast from his listless performance two weeks ago that appeared to damage his re-election prospects.

Mr Obama blasted Mr Romney's economic plans as damaging to the middle class and accused him of flip-flopping on issues like energy and gun control.

He appeared angry - a rare emotion seen in the famously cool Mr Obama - when Mr Romney, a former Massachusetts governor, criticised his response to the deadly attack that killed the US ambassador to Libya and three other Americans at the US Consulate in Benghazi last month.

He pointedly told Mr Romney that any suggestion that his administration "would play politics or mislead when we've lost four of our own, governor, is offensive. That's not what we do".

The stakes of the town hall-style debate at Hofstra University, just outside New York, could not have been higher.

With just three weeks to go before Election Day, the race is locked in a dead heat and many Americans are already casting ballots in states that allow early voting.

The open-stage format, with no physical objects between them, placed incumbent and challenger face to face and, when they chose, directly in each other's faces.

Their physical encounters crackled with energy and tension, and the crowd watched raptly as the two sparred while struggling to appear calm and affable before a national television audience of tens of millions.

It is not clear whether the debate will help Mr Obama regain the momentum he lost after his poor performance in the October 3 debate, which helped fuel a rise in opinion polls by Mr Romney.

But his forcefulness was bound to cheer supporters disheartened by his previous performance.

Mr Romney also gave his supporters reasons to cheer. He appeared confident and comfortable, as he had been in the first debate, and aggressively returned Mr Obama's fire.

Mr Romney said the middle class "has been crushed over the last four years", and that 23 million Americans are struggling to find work.

Economic growth has been slow throughout Mr Obama's term in office, and unemployment only recently dipped below 8% for the first time since he moved into the White House.

Mr Romney noted that if out-of-work Americans who no longer look for jobs were counted, the unemployment rate would be 10.7%.

Mr Romney described the deadly Libya attack as part of an unravelling of the administration's foreign policy.

He said it took Mr Obama a long time to admit the episode had been a terrorist attack, but Mr Obama said he had said so the day after the attack in an appearance at the White House.

When moderator Candy Crowley of CNN said the president had in fact done so, Mr Obama, prompted: "Say that a little louder, Candy."

Mr Romney also repeated a pledge to declare China a currency manipulator on his first day in office.

"We can compete with anyone in the world as long as the playing field is level," he said.

"China's been cheating over the years" by holding down the value of its currency and stealing intellectual property.

Mr Obama told Mr Romney that "you're the last person who's going to get tough on China".

He has charged that Mr Romney made money from companies that outsourced jobs to China while running the private equity firm Bain Capital.

The two men interrupted one another often, speaking over each other to the point that neither could be understood.

"You'll get your chance in a moment. I'm still speaking," Mr Romney said as he tried to cut off Mr Obama at one point.

Mr Obama is fighting to hang on to small leads in many of the nine key swing states that likely will decide the election.

The so-called battleground states - those that do not reliably vote either Republican or Democratic - take on outsized importance in the US system, in which presidents are chosen not by the nationwide popular vote but in state-by-state contests.

From the opening moments, Mr Obama was aggressive. He criticised Mr Romney's opposition to the Democrats' bailout of the car industry and rejected Mr Romney's economic proposals as squeezing the middle class.

"Governor Romney says he's got a five-point plan. Governor Romney doesn't have a five-point plan. He has a one-point plan. And that plan is to make sure that folks at the top play by a different set of rules," Mr Obama said.

The debate was before an audience of 80 uncommitted voters selected by the Gallup Organisation who posed questions to the candidates. Ms Crowley chose speakers after reviewing their proposed questions to avoid repeats.

Mr Obama needed to strike the right balance in coming on strong against Mr Romney without turning off the audience and millions of television viewers by going too negative. Mr Obama has said his first debate performance was "too polite".

While most of the debate was focused on policy differences, there was one more-personal moment, when Mr Obama raised the issue of Mr Romney's investments in China.

"Mr President, have you looked at your pension?" Mr Romney interrupted.

"You know, I don't look at my pension. It's not as big as yours," shot back Mr Obama to his wealthier rival.

Only one more debate, next Monday, remains and that one deals with foreign policy.