Mitt Romney and Barack Obama at the US second presidential debate. Reuters

Barack Obama secured the comeback he desperately needed in the second presidential debate against Mitt Romney, finishing the night on top after a series of fierce clashes in which the two made no attempt to hide the extent of their personal hostility.

At one point in the 90-minute debate, watched by tens of millions of Americans, the two squared off, only a few feet apart, talking over one another, jabbing fingers at one another and accusing each other of lying.

Deriding Romney for what the Obama campaign sees as a belated shift to the centre, Obama portrayed him as more extreme than George W Bush on social issues, particularly women's rights.

Obama needed a big performance after his dismal failure in the first presidential debate in Denver. That 3 October debate was dominated by Romney and started the president's poll slide, leaving the two in a dead heat less than three weeks from election day.

Obama will have lifted Democratic morale and may have done enough to slow – or even arrest – the crisis.

It will be several days before the first reliable polls appear but a snap poll by CNN awarded the debate 46% to Obama and 39% to Romney, while CBS put it as 37% Obama to 30% Romney.

Obama, listless in Denver, was transformed in the second debate: focused, animated and combative. The president grew in confidence in the later stages of the night, while Romney, confident at the start, began to fade.

Obama's campaign team said Obama turned in the peformance it had expected him to produce two weeks ago.

The former White House spokesman, Robert Gibbs, reinstated to the Obama team as an adviser, said: "The president knew he did not do well two weeks ago. He knew he had to step up his game tonight and Mitt Romney was left looking uncomfortable".

Republicans countered that nothing the president said will have changed the dynamic of the race.

Romney and Obama now have a presidential debate victory apiece going into the final one, usually the most watched of the three, in Boca Raton, Florida, on Monday.

The two men clashed in the second debate – at Hofstra University, Long Island – over tax, energy, women's rights, immigration and Libya.

Obama taunted Romney over the vagueness of his plans for tax cuts and deficit reduction. "If somebody came to you, governor, with a plan that said, 'Here, I want to spend seven or eight trillion dollars, and we're going to pay for it, but we can't tell you until maybe after the election how we're going to do it,' you wouldn't have taken such a sketchy deal, and neither should you, the American people," Obama said.

But the most politically damaging moment for Romney came when he bungled his attack on the Obama administration's handling of the assault on the Benghazi consulate in which the US ambassador Chris Stevens and three other Americans were killed.

It should have been an easy one for Romney, after days of shifting accounts from administration officials who initially blamed the attack on a protest over an Islamophobic film but have now conceded it was a pre-planned terrorist attack.

Romney accused Obama of flying off on fund-raising trips the day after the Benghazi killings.

But Obama came back forcefully, accepting the buck stopped with him, not with Hillary Clinton or anyone else in his administration. "Secretary Clinton has done an extraordinary job. But she works for me. I'm the president and I'm always responsible, and that's why nobody's more interested in finding out exactly what happened." He described as "offensive" Romney seeking to suggest that as president he was acting out of political motivation over the deaths of four Americans.

Then, when Romney tried to challenge the president over his assertion that he had described it as an act of terror on the morning after the attack, the moderator Candy Crowley intervened to say that Obama was correct. "He did, in fact, sir," she told Romney, who was unable to counter-attack.

Crowley, CNN's chief political correspondent and the first woman in two decades to moderate a presidential debate, went on to point out that it had taken two weeks for the administration to abandon the idea that the attacks were related to protests over the anti-Muslim video. But her intervention left conservatives furious, with one Republican strategist describing it as the most egregious error by a debate moderator ever.

Obama also hit home in an exchange over Romney's investments in China. When the Republican responded that Obama should look at the investments in his own pension, Obama, with his trademark grin, shot back: "I don't look at my pension. It's not as big as yours."

The power of the quip was that it encapsulated the image the Democrats have been labouring to put across of Romney as rich and elitist, in a different league from the majority of Americans.

In the final minutes, to the relief of Democrats, Obama also mentioned the secret video in which Romney dismissed 47% of American voters as freeloaders. The president had dismayed Democrats when he failed to raise it in the Denver debate.

The format, a town-hall debate with questions from the audience, makes exchanges between the two awkward and supposedly encourages civil exchanges. From the start Obama and Romney dispensed with tradition, rising from their seats to engage first with the questioners and then one another.

During a discussion about lack of drilling for oil on federal land, the two could barely contain themselves, confronting one another just a few feet apart, almost eye-balling one another, with Obama saying "not true" while Romney insisted it was "absolutely true".

Until then it was thought the animosity between the two was confined to policy but it became apparent there is also deep personal antipathy. At one point Romney, almost contemptuous of the president, told him: "You will get your chance in a minute. I am speaking." Republicans may view this as Romney standing up to Obama and what they regard as a representative of the liberal media, but the risk is that independents view it as rudeness.

In the early exchanges Romney held his own, at one point witheringly telling Obama that whatever he said he would do in his second term, his first term suggested otherwise.

But his difficulties began with a question from an audience member over what the candidates would do to improve conditions for working women. He replied by talking about his time as governor of Massachusetts when he appointed many women into cabinet roles and had commissioned a study on women leaders. But he then delivered an unfortunate line when he said that he had looked through "whole binders full of women" when seeking to recruit cabinet members as Massachusetts governor.

Romney also clashed repeatedly with Crowley over the rules and how much time he was being given to answer questions.

In the spin room afterwards David Axelrod, Obama's campaign adviser, said Romney had been "cornered and ran out of the room. It was clear to the American people he was exposed tonight."

Romney's adviser, Ed Gillespie, said: "The momentum continues for Governor Romney." Asked about Romney's failure to control the debate as he had in Denver, he said: "I don't think it changes the dynamic. This was never about style. It is about substance – jobs – and that has not changed."