McCain countered by saying that the next president shouldn't look back and parse the past.
"The next president of the United States is not going to have to address the issue as to whether we went into Iraq or not," McCain said. "The next president of the United States is going to have to decide how we leave, when we leave, and what we leave behind.".
The Illinois senator also reiterated his call for more troops in Afghanistan, citing reports from commanders on the ground that the situation is getting worse -- and he accused McCain of an inconsistent approach towards the country.
"We took our eye off Afghanistan," Obama said. "We took our eye off the folks who perpetrated 9/11. They are still sending out videotapes. And, Sen. McCain, nobody is talking about defeat in Iraq, but I have to say we are having enormous problems in Afghanistan because of that decision."
But McCain fired back, saying that his travels through the tribal regions in Afghanistan give him a better perspective on the security needs there.
"So the point is that we will prevail in Afghanistan," McCain said, "but we need the new strategy and we need it to succeed."
McCain went on to deride Obama's plan for troop withdrawal from Iraq.
"If we suffer defeat in Iraq, which Gen. [David] Petraeus predicts we will if we adopted Sen. Obama's set date for withdrawal, then that will have a calamitous effect in Afghanistan, and [on] American national security interests in the region," McCain said. "Sen. Obama doesn't seem to understand there is a connected between the two."
The candidates also offered their overall impressions on U.S. national security.
"I think ... that we have a safer nation [since 9/11], but we are a long way from safe," McCain said.
The Vietnam War veteran, who faced torture as a prisoner of war, stressed the need for well-trained interrogators, "so that we don't ever torture a prisoner ever again.
"We have to make sure that our technological and intelligence capabilities are better," he added. "We have to work more closely with our allies. I know our allies, and I can work much more closely with them."
He also cited his push to form the 9/11 commission as an instance when he met strong opposition from the Bush administration.
Obama agreed that the country is safer now, but added that even though billions have been poured into airport security and potential terror targets have been identified, there are still weak spots, such as chemical sites, transportation systems and ports that need better security.
"And the biggest threat that we face right now is not a nuclear missile coming over the skies," he said. "It's in a suitcase.
"This is why the issue of nuclear proliferation is so important," he added. "The biggest threat to the United States is a terrorist getting their hands on nuclear weapons."
Obama also faulted the Bush administration for fostering a negative perception of the United States in the world, claiming that the world view of this country "is going to make a difference, in terms of our capacity to get cooperation and root out terrorism."
And then things got a little ugly.
Obama tweaked McCain's misstatement earlier this month in an interview when the Republican said he was not sure he would be willing to meet with the prime minister of Spain.