HEMPSTEAD, N.Y. — No one thought the second debate between President Obama and Mitt Romney would be like the first one, and it certainly wasn’t. The question is how much Tuesday’s sharply contested forum will arrest the movement toward Romney that has shaken up the race in the past two weeks.

Unlike the exchange in Denver, Tuesday’s debate at Hofstra University was not a mismatch between an aggressive and focused Romney and a lackluster and unfocused Obama. Instead, it was marked by tough and testy exchanges between two candidates who have opposing policies and who knew they had much to lose if they didn’t do well.

Unlike in the first debate, Romney was on the defensive as much as or more than he was on the offensive. It was clear from the opening minutes Tuesday that Democrats, who were deeply disappointed by Obama’s performance in Denver, were elated by the president they saw on stage. He passed up no opportunity to attack his rival and to challenge his record, just as Romney had done last time.

The candidates did not come to play nice. They squabbled over facts. They interrupted each other. They circled each other. They invaded each other’s space. If town-hall-style debates are supposed to be forums in which the candidates focus on the voters onstage, this was one in which they often seemed to ignore their questioners so they could slug it out one on one.

Romney and Obama have one more debate, on Monday at Lynn University in Boca Raton, Fla. Although the focus of the final forum is foreign policy, it will be a time for the candidates to make their closing arguments to try to woo undecided voters and motivate their respective bases, whose enthusiasm becomes crucial in a close contest.

But after what happened at Hofstra, it’s clear that the real competition will be the fight to the finish, a battle for the battleground states where the election will be decided. The most important are Virginia, Florida and Ohio — with Ohio being perhaps first among equals. After that come Iowa, Colorado and New Hampshire, Nevada, North Carolina and Wisconsin.

Few events have changed the race as quickly or dramatically as the first debate. Romney’s clear victory over Obama in Denver turned around the campaign narrative, which was heading toward a premature conclusion that the contest was virtually over. It also shifted polls, both nationally and in the battleground states.

How many minds will be changed by what happened on Tuesday night? There is likely to be a boost in enthusiasm among Obama loyalists, and that’s not insignificant. Given that some parts of his coalition, young voters in particular, are not as motivated as they were four years ago, that jolt of energy could be important. Obama advisers know that turning out their voters will be harder for them than it will be for Romney’s team.

But Romney’s initial performance did much to generate enthusiasm among his supporters. That’s not likely to be diminished by Tuesday’s debate. After Denver, Republicans began to think it was possible to win. Their enthusiasm going forward is unlikely to slacken. The turnout battle from now until Election Day will be as fiercely fought as was the battle at Hofstra.

One of the keys to the outcome will be women, and a big question from Tuesday’s debate is how women will react to what they saw. Romney appeared to be making progress in reducing Obama’s big margins among female voters in the past two weeks. But he may have hurt himself.

Just as Vice President Biden’s smiles and laughs during his debate with GOP vice presidential nominee Paul Ryan (Wis.) last week turned off some voters, Romney’s efforts to push back against CNN’s Candy Crowley, who served as moderator, could alienate some women.

Heading into the second debate, there was little disagreement that a race that had seemed to be slipping away from Romney in September was back to what strategists in both parties had predicted would be a competitive contest to the end.

In the hours before the exchange, the Romney and Obama campaigns offered genuinely conflicting and perhaps self-serving assessments of how things stood — in the battlegrounds and among key demographic groups.

Take the state of play in Ohio. Before Denver, Obama had a clear and, in some polls, big lead. In a pre-debate appearance Tuesday in the spin room, Sen. Rob Portman (R-Ohio) told reporters that the race there was even. “Our own tracking indicates it’s a dead heat,” he said.

Portman, who has played the president in Romney’s debate preparations, said that before Denver, the challenger was behind by “a big gap,” but added that Romney has made steady progress since then. “Frankly, it wasn’t just a bump after the debate.”

Jim Messina, Obama’s campaign manager, offered a counterview. He said the first debate may have tightened the race, but added that the contest always was destined to close in the final month. He also said that Obama was still strong in the Midwest — Ohio, Iowa and Wisconsin.

“We continue to have more pathways to 270 votes than Romney,” he said. “All of our pathways are still there. We are where we need to be.”

What voters saw Tuesday night was just how big the choice will be in November. Romney and Obama painted dire pictures of what will happen if the other is elected in three weeks. Voters may have heard this before, but it was more sharply etched, with the candidates standing only a few feet apart, than in the television commercials or campaign appearances.

Now the campaign turns to fundamentals — one more debate and then a sprint to Nov. 6. The race has been long and hard-fought, but Obama and Romney showed Tuesday night that they have plenty left for the final stretch, and their teams are ready for what comes next.