(Reuters) - President Barack Obama and Republican rival Mitt Romney clashed repeatedly on jobs, energy and Libya in their second debate on Tuesday, with Obama moving aggressively to challenge his opponent.

Obama was much sharper and more energetic than in their first encounter two weeks ago, when his listless performance was heavily criticized and gave Romney's campaign a much-needed boost.

The Democrat fought back against accusations by his rival that he had played down the attack by Islamist militants in Libya last month that killed four Americans, including the U.S. Ambassador Chris Stevens.

"I'm the president and I'm always responsible," Obama said. The two men argued over whether Obama had described the Libya attack as terrorism or not.

Romney accused his opponent of overseeing a stagnant economy. "The middle class has been crushed over the last four years and jobs have been too scarce," the former Massachusetts governor said.

"I know what it takes to get this economy going," he said. "I know what it takes to create good jobs again."

bama repeatedly accused Romney of misstating his policies as president, and resurrected his charge that the economic proposals put forward by the former private equity executive were designed to protect and bolster the wealthy at the expense of the middle class.

The debate at Hofstra University in Hempstead, N.Y., was in an intimate town-hall format, in which some of more than 80 undecided local voters from New York state's Nassau County asked questions.

Both candidates were able to roam the stage to talk directly to the questioners, and at times they circled each other warily like prize fighters.

Romney approached Obama at one point to ask repeatedly if licenses and permits for energy drilling on federal land had been reduced during his administration.

The Republican's strong performance in the first debate helped him catch up to Obama and recent surveys have put the race for the White House at a virtual dead heat just three weeks ahead of the November 6 election.

Obama seems to have stopped the slide in polls after the last debate. In a Reuters/Ipsos daily tracking poll released before the debate on Tuesday, he gained a bit more ground on Romney for the third straight day and led 46 percent to 43 percent. But a Gallup/USA Today poll showed Romney ahead by 4 percentage points in the 12 most contested states.

Romney, a wealthy former private equity executive often accused of failing to connect with ordinary people, stayed on the offensive but frequently asked the moderator for more time to answer Obama.