President Obama delivered a far more forceful performance in his second presidential debate against Mitt Romney, as he and the former Massachusetts governor clashed over a wide range of questions from undecided voters.

Debating at Hofstra University in New York’s Long Island, Mr. Obama and Mr. Romney both had the gloves off in this town-hall debate, as they sparred over questions that ranged from the economy and gasoline prices to Libya, immigration, gun control, and gender disparity in pay.

The outcome was less clear-cut than that of the debate in Denver, with neither candidate scoring the huge victory that Romney seemed to in their last encounter.

The big question as the debate began was whether Obama could undo some of the damage he did two weeks ago in Denver, where he was widely viewed as losing badly to Romney. In the weeks since that debate, Romney has largely overtaken Obama in the polls and is now leading in some key swing states. Obama certainly delivered a stronger performance this time around, and seemed unafraid of confronting Romney on a number of issues he had shied away from two weeks ago.

“Very little of what Governor Romney just said is true,” he said early on in the debate, in response to criticisms by Romney of his energy policy and statements that he had reduced oil and gas drilling on federal lands.

It set the stage for a willingness to spar with Romney – an interaction that often doesn’t happen in town-hall debates, where the emphasis is on engaging with the questioner – and it happened repeatedly through the night, as Romney and Obama tussled with each other about their positions and statements on energy, the Libya attack, immigration, and tax policy.

Romney’s strongest moments in the debate came when he characterized Obama’s first four years in stark terms.

“I think you know that these last four years haven't been so good as the president just described and that you don't feel like you’re confident that the next four years are going to be much better either,” Romney told a questioner who said he had voted for Obama four years ago but was less optimistic this time around.

“I can tell you that if you were to elect President Obama, you know what you're going to get,” Romney said, before launching into criticisms ranging from unemployment and the growing numbers of people in poverty to his failure to reform entitlement programs or immigration. “The president has tried, but his policies haven't worked,” Romney said.

Romney was strong at the debate's end, too, though he misfired notably when he answered a question on gender pay inequity by referring to “whole binders full of women” that he had his staff in the Massachusetts governor’s office bring him when there weren’t enough women candidates for cabinet positions. The phrase quickly became one of the most mocked of the night on Twitter and elsewhere.

But Obama, who had the most to gain from this debate, came in with a particularly tall agenda.

He needed to be more energetic than he had been in Denver. He needed to find a way to attack Romney’s character and paint him as a flip-flopper, without hurting his own likability. He needed to appeal to women voters, who are key to his victory plan and who polls show may be leaving the president for Romney.

And he had to do it all without seeming as if he was overcompensating from his weak performance of two weeks ago, or that he is desperate.

And, with some missteps, he accomplished most of that agenda.

He used a fairly softball question on pay disparity for women not only to highlight his signing of the Lilly Ledbetter Act but also to move into a discussion of contraception and Planned Parenthood – criticizing Romney on both – noting that “these are not just women's issues. These are family issues. These are economic issues.”

Moderator Candy Crowley, a CNN news correspondent, was nearly as forceful in this debate as the two candidates.

There were questions before the debate began about the role Ms. Crowley would play, with both campaigns saying that the agreement stipulated that she would do nothing more than invite questions from the audience members and keep the candidates to their time limits, while Crowley said that there was, in fact, room for her to ask follow-up questions and facilitate discussion.

And in fact, she was a strong presence, frequently interrupting the candidates – who didn’t always listen to her – to bring them back to point or ask them to wrap things up, as well as asking pointed follow-up questions. In one case, she asked Romney what he would do if, in fact, the numbers on his tax plan don’t add up (as Obama contends) – a possibility Romney refused to entertain – and in another case pushed Obama to answer Romney’s claim that gas prices shouldn’t be at $4 a gallon if his energy policies were working.

In the most notable exchange, Crowley actually stepped in as a spontaneous fact checker, as Obama and Romney sparred about whether he called the attack on the US Consulate in Benghazi, Libya, an act of terror.

Romney jumped on Obama’s claim that he stood in the Rose Garden the day after the attack and called it “an act of terror,” saying that, in fact, Obama had waited 14 days before he used that description.

The two candidates sparred briefly – as they did several times during the debate in direct confrontations – with Obama telling Romney at one point to “get the transcript,” before Crowley finally stepped in, saying, “He did, in fact, sir.”

“Can you say that a little louder, Candy?” Obama immediately asked, as some in the audience applauded.

It was one of the more indelible moments of a debate that overall saw strong performances by both candidates, and is likely to be replayed often in the coming days.

It also is likely to be among the most questioned, particularly by Republicans citing media (and moderator) bias. Even Crowley, speaking on CNN after the debate, admitted that Romney “was right in the main” in how he characterized Obama’s depictions of the Benghazi attacks, but “just picked the wrong word.” (In the Rose Garden address, Obama did refer to “acts of terror,” but only in general terms.)

For Romney, though, who surely entered the debate hoping to hammer Obama on Libya, it was ultimately a lost opportunity. What most viewers are likely to take away is that Romney was called out, and appeared to lose.

The two candidates, who seemed to exhibit a strong dislike of each other on stage, engaged in a number of confrontations throughout the night, frequently posing questions to each other (something else supposedly prohibited in the debate guidelines) and occasionally entering personal space.

At one point, Romney repeatedly asked Obama, “Have you looked at your pension?,” as he implied that Obama also had investments outside the United States. Finally Obama replied, tersely, “I don't look at my pension. It's not as big as yours, so it doesn't take as long.”

Obama surprised many viewers in Denver by refraining from mentioning Romney’s infamous “47 percent” comment, in which Romney seemed in private remarks to dismiss nearly half the population who don’t pay federal income taxes.

On Long Island, it at first seemed that the president was going to refrain again from bringing them up – and in fact, Romney used his final question to offer a tacit rebuttal of his remarks, telling the audience that, “I care about 100 percent of the American people.”

But then Obama, who was awarded the last word, used his final answer to hammer Romney hard on those remarks, reminding viewers that Romney “said behind closed doors that 47 percent of this country consider themselves victims.”

“Think about who he was talking about,” he urged his audience.

It was a strong close for the president, though in the end, Americans viewing this debate are likely to be split along far more partisan lines in whom they consider the winner than they were two weeks ago.

Most snap polls conducted by news organizations after the debate seemed to give the victory to Obama, though those polls can have a high degree of error, and the effects are usually sorted out in the coming days.