— A far more aggressive President Obama showed up for his second debate with Mitt Romney on Tuesday, and at moments their town-hall-style engagement felt more like a shouting match than a presidential debate.

The two men challenged each other on the facts, talked over each other and stalked each other across the stage.

Moderator Candy Crowley of CNN faced a difficult task all night in trying to keep to the intended format as both candidates insisted on answering nearly every charge from his opponent, regardless of the time limits.

The president, looking for an opportunity to recharge his campaign after a lackluster performance at their first debate two weeks earlier, contended that the Republican nominee’s policies and values are extreme and out of touch with the concerns of the middle class.

Romney, having rallied his supporters with his performance in Denver, was seeking to keep that momentum going. Neither one held back.

The debate, which was framed by questions from the audience, ranged into topics that had not been broached in any depth at the earlier one — including immigration, women’s issues, gun control and foreign policy.

In one of the sharpest exchanges of the night, Obama and Romney clashed over whether the White House misled Americans about the nature of the Sept. 11 attack on a U.S. diplomatic outpost in Benghazi, Libya.

The debate’s first questioner, a college student who will graduate soon, asked Romney how he would ensure that he could get a job and pay off student loans. “We have to make it easier for kids to afford college and, once they graduate from college, to get a job,” Romney said, coming down off his stool in the town-hall setting of the debate. “What’s happened over the last four years has been very, very hard for America’s young people.” But Obama, while agreeing that improving higher education is essential for the nation’s economic future, noted pointedly that he wants to create manufacturing jobs like those in the auto industry that he helped preserve with a federal bailout that Romney opposed.

The tone was established early in the debate, when a woman in the audience asked Romney to specify the tax deductions he would eliminate to pay for the tax rate reductions he has promised. As he has in the past, Romney raised the possibility of an overall cap: “I’ll pick a number — $25,000 of deductions and credits, and you can decide which ones to use.”

Obama seized on Romney’s lack of specificity as a “sketchy deal” and contended it was based on “math that doesn’t add up.” He also noted that Romney, who is worth hundreds of millions of dollars, pays a lower tax rate than many middle-income people.

“Well, of course they add up,” Romney retorted, citing his successful business career and the budgets he balanced as Massachusetts governor. “When we’re talking about math that doesn’t add up, how about $4 trillion of deficits over the last four years, $5 trillion? That’s math that doesn’t add up.”

Obama made other references to Romney’s wealth. In one exchange, Romney noted that the president, too, had investments in Chinese companies.

“Mr. President, have you looked at your pension?” Romney said.

“I don’t look at my pension,” Obama responded. “It’s not as big as yours, so it doesn’t take as long. I don’t check it that often.”

Later, Obama raised Romney’s remarks to wealthy donors at a private fundraiser disparaging “the 47 percent” of Americans who do not pay income taxes. It was a line of attack that he didn’t make in the previous debate, which mystified many of his allies.

“I believe Governor Romney is a good man — loves his family, cares about his faith,” Obama said. “But I also believe that when he said behind closed doors that 47 percent of the country considered themselves victims who refuse personal responsibility, think about who he was talking about.”

Obama, mentioning people on Social Security, soldiers and veterans, as well as students, said: “I want to fight for them. That’s what I’ve been doing for the last four years. Because if they succeed, I believe the country succeeds.”

Romney said the president and his campaign were trying to characterize him “as someone who’s very different than who I am.”

“I care about 100 percent of the American people,” Romney said. “I want 100 percent of the American people to have a bright and prosperous future. I care about our kids. I understand what it takes to make a bright and prosperous future for America again.”

The former Massachusetts governor seemed most confident when he talked about Obama’s stewardship of the nation’s beleaguered economy.

When a man who voted for Obama in 2008 said his everyday living expenses had grown too high, Romney told him, “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 cast Obama as a president who failed to deliver on his promises — to lower the unemployment rate, to cut the deficit, to lift people out of poverty and to create more jobs.

“The middle class is getting crushed under the policies of a president who has not understood what it takes to get the economy working again,” Romney said.

Romney continued to present a more moderate side than he did during the Republican primaries, a shift that became apparent during the last debate. When a young man asked how he would ensure he could get a job when he gets out of college, he mentioned government programs such as Pell grants and scholarships.

He also distanced himself from the policies of George W. Bush, the last Republican president, saying he would balance the budget, crack down on China and focus more on small business.

Obama, however, contended that Romney is more extreme than Bush.

“George Bush didn’t propose turning Medicare into a voucher. George Bush embraced comprehensive immigration reform. He didn’t call for self-deportation,” Obama said. “George Bush never suggested that we eliminate funding for Planned Parenthood, so there are differences between Governor Romney and George Bush, but they’re not on economic policy. In some ways, he’s gone to a more extreme place when it comes to social policy.”

Obama used many of his questions as pivot points to paint Romney as extreme on a wide range of social issues — particularly ones that appeal to the female vote, which is crucial to the president’s prospects and which some polls suggest has begun to slip away from him.

When asked about the equality of women’s pay, Obama raised Romney’s opposition to abortion rights and his pledge to take federal funds from Planned Parenthood. Obama said Romney “feels comfortable having politicians in Washington decide the health-care choices that women are making.”

On Libya, the president said he is “ultimately responsible for what’s taking place there” but bristled at the suggestion from Romney that he had withheld critical facts about the incident.

“The suggestion that anyone on my team . . . would play politics or mislead is offensive,” said Obama, his voice rising. He noted that he addressed the American people from the Rose Garden the day after the Benghazi attack and called it “an act of terror, and I also said that we’re going to hunt down those who committed this crime.”

Sensing an opportunity, Romney said, “I want to make sure we get that for the record, because it took the president 14 days before he called the attack in Benghazi an act of terror.”

Then came Obama’s retort: “Get the transcript.”

Crowley interjected that Obama did, in fact, call it an act of terror, although it did take days for the administration to concede that the terrorist act was unrelated to initial reports of anger at a video that defamed the prophet Muhammad.

In their earlier debate, Romney had come off better-prepared, energized and self-assured. The president, on the other hand, seemed disengaged.

“Governor Romney had a good night. I had a bad night,” the president later acknowledged in an interview with ABC News.

The most recent Washington Post-ABC News poll shows the race remains a close one, with Obama at 49 percent and Romney at 46 percent among likely voters nationally.

But the enthusiasm that Romney’s supporters express for him rose markedly, and a number of other surveys suggest he is pulling even or even slightly ahead of the president in some of the swing states that will determine the election outcome.

The debate’s “town hall” forum presented a different kind of challenge for the candidates. It required them to answer questions posed directly by an audience of 82 undecided voters from the New York area, screened and selected by the Gallup polling organization.

The pitfalls and opportunities of that format are famous — legendarily so in 1992, when President George H.W. Bush was caught on camera checking his watch, while his opponent Bill Clinton made the most of his gift of connecting personally with voters .

That kind of voter interaction of a town hall, televised nationally, has generally meant that the contenders have less leeway to dodge and fall back on their talking points.

In that setting, too, the conventional wisdom has it that candidates have to be mindful of getting too aggressive. It was clear Tuesday that neither Obama nor Romney subscribed to that more conventional, cautious approach.

Their final debate, which will center on foreign policy, is set for Monday in Boca Raton, Fla.