WASHINGTON (MarketWatch) — Barack Obama won the debate and got his campaign back on track.

The presidential election is far from over, but the president accomplished his major goals during Tuesday’s town-hall-style debate with Republican candidate Mitt Romney.

After his dominating performance Tuesday, no one is talking about the sleepwalking president anymore. If anything, they’re calling him a bully for the way he slapped Romney around.

Both candidates were energized and gave spirited responses to the questions from undecided voters. Each launched attacks on the other’s record, policies and even character.

That’s what you’d expect to see from a couple of pros, even if Obama had had a horrible night the last time out.

As expected, Romney kept it pretty simple with his critique of Obama’s economic policy: The last four years have been terrible, and the next four will be just as bad if Obama is re-elected.

If Romney could have kept the debate focused on the unemployment rate, the poverty rate and the food-stamp rate, he might have won it by simply repeating over and over all night long that 23 million Americans are struggling to find a decent job, 23 million Americans are struggling to find a decent job, 23 million Americans are struggling to find a decent job. See counterpoint by Diana Furchtgott-Roth: Romney’s tax plan will drive business growth.

What was unexpected was the unforced errors Romney made.

President Obama speaks as Republican nominee Romney waits to respond. Reuters

As the discussion veered away from the narrow question of jobs, Romney lost his footing. He stumbled badly on Libya, on gun control, on immigration and on broadly defined “women’s issues.”

And, in the end, Romney himself alluded to a notion that had been so obviously missing from the first two hours and 58 minutes of debates: that 47% of Americans are dead to Mitt Romney. Bad move, Mitt.

Obama, on the other hand, managed to remind voters why they liked him in the first place: He’s smart, charming and caring.

Obama knew he had to recover from the disaster in Denver two weeks ago. Not only did Obama need to show a little enthusiasm for the job; he had to project a positive optimistic vision of his own while simultaneously pushing back forcefully at the holes in Romney’s arguments.

Ahead of this second debate, the pundits, pollsters and party operatives said Obama had to accomplish seven difficult tasks to save his campaign for re-election: He needed to be energetic. He needed to be likable. He needed to show empathy. He needed to be factual. He needed to call Romney out when the latter exaggerated. He needed to contest the debate on the issues where he’s stronger. And he needed to project a positive vision for America.

Obama’s case for a second term

To one degree or another, Obama accomplished all seven tasks. He was more energetic and enthusiastic. The format of the debate allowed him to empathize directly with voters. He was aggressive from the opening question in challenging Romney on his facts. He was able to pivot the discussion away from unfriendly topics like deficits and toward issues like equal pay, reproductive rights, immigration and inequality.

But most importantly, Obama was able to talk with some passion about why he wants to be president for the next four years.

He said he’s doing it for the 47% of Americans, the ones that Romney has written off, but who are veterans who fought our wars, the seniors who built the nation, the children who hold the promise of our future, and the workers and dreamers who keep getting up after they’ve been knocked down.

“And I want to fight for them,” Obama said, “because, if they succeed, I believe the country succeeds.”