(CNN) -- Sens. John McCain and Barack Obama hammered away at each other's judgment on the economy, domestic policy and foreign affairs as they faced off in their second presidential debate.
Obama tried to tie McCain to President Bush's "failed" policies, while McCain pushed his image as a "consistent reformer" at the debate, which took place at Belmont University in Nashville, Tennessee.
The debate was set up as a town hall meeting, and the audience was made up of undecided voters.
The candidates spoke directly to each other at times, but at other times they spoke as if their opponent were not on the same stage, a few feet away. Debate report card
In comparison to the first debate, Tuesday's event -- which came on the heels of several days of increasingly aggressive attacks from both sides -- took on a more contentious tone.
On foreign policy, McCain charged that Obama "does not understand" the country's national security challenges.
McCain said he knows how to handle foreign affairs and questioned Obama's ability to do so. Analysts weigh in on the debate »
"Sen. Obama was wrong about Iraq and the surge. He was wrong about Russia when they committed aggression against Georgia. And in his short career, he does not understand our national security challenges," McCain said. "We don't have time for on-the-job training, my friends."
McCain said the "challenge" facing a president considering using military force "is to know when to go in and when not."
"My judgment is something that I think I have a record to stand on," McCain said. Video highlights of key moments »
Obama shot back and questioned McCain's judgment in supporting the invasion of Iraq.
"When Sen. McCain was cheerleading the president to go into Iraq, he suggested it was going to be quick and easy, we'd be greeted as liberators," he said. "That was the wrong judgment, and it's been costly to us."
The candidates spent about 30 minutes of the debate focusing on foreign affairs. They spoke about the economy for about 45 minutes and spent 15 minutes discussing domestic issues. See scenes from the debate »
A national poll of debate watchers suggested that Obama won the presidential debate. Post-debate poll
Fifty-four percent of those questioned in a CNN/Opinion Research Corp. survey released 30 minutes after the end of the debate said that Obama did the best job, while 30 percent said McCain performed better.
The CNN/Opinion Research Corp. poll was conducted by telephone with 675 adult Americans who watched the debate. All interviews were taken after the end of the debate. The survey's sampling error is plus or minus 4 percentage points. iReport.com: Tell us who you think won round two
At the start of the debate, Obama said the country is in the worst financial crisis since the Great Depression.
He blamed President Bush and McCain for the crisis, saying they had worked to "strip away regulation." Bush: The elephant in the room
McCain said the system in Washington "cries out for bipartisanship" and pushed his record as a reformer.
He proposed having the government buy up and renegotiate bad home loans to stabilize the property market. He admitted the plan would be expensive but said it was necessary. Watch McCain talk about his plan for the economy »
The Arizona senator also hammered away at his rival's tax policies, saying that "nailing down Sen. Obama's various tax proposals is like nailing Jell-O to the wall." Watch McCain slam Obama's tax plan »
McCain charged that "Obama's secret that you don't know" is that he would increase taxes on small business revenue, which he said would lead to job cuts. Fact check: Did Obama vote 94 times for higher taxes
Obama shot back, saying "the Straight Talk Express lost a wheel on that one."
"Let's be clear about my tax plan and Sen. McCain's," he said. "I want to provide a tax cut for 95 percent of Americans." Watch Obama talk about his plan for the middle class »
The candidates talked about their plans to revamp the health care system.
Obama said the country has a "moral commitment as well as an economic imperative" to address the health care problem.
The Illinois senator said health care is a "crushing burden" for small businesses and is "breaking family budgets."
Obama said health care was a "right," while McCain said it was a "responsibility." Watch the candidates debate health care »
Obama and McCain both proposed computerizing medical records to reduce costs and limit errors.
Obama's health care plan includes the creation of a national health insurance program for individuals who do not have employer-provided health care and who do not qualify for other existing federal programs. His plan does not mandate individual coverage for all Americans, but requires coverage for all children.
McCain opposes federally mandated universal coverage. He believes competition will improve the quality of health insurance.
McCain says he would reform the tax code to offer choices beyond employee-based health insurance coverage.
McCain argued that Obama's plan included fines for small businesses that did not insure their employees, while his was based on "choice" rather than "mandates."
Immediately after the debate, Obama's campaign highlighted a moment when McCain sought to criticize Obama for supporting the 2007 Bush-Cheney energy bill:
"It was an energy bill on the floor of the Senate, loaded down with goodies, billions for the oil companies, and it was sponsored by Bush and Cheney," McCain said.
"You know who voted for it? You might never know. That one. You know who voted against it? Me."
Obama campaign spokesman Bill Burton immediately e-mailed reporters noting McCain's seemingly peculiar reference to the Illinois senator.
"Did John McCain just refer to Obama as 'that one?'" Burton asked. Obama campaign highlights 'that one'
McCain and Obama will face off for a third and final time next Wednesday at Hofstra University in Hempstead, New York.