Senator John McCain, looking ahead to a possible general-election matchup with Senator Barack Obama, attacked Mr. Obama on Wednesday for what he called a weak and naïve approach to the conflict in Iraq and the effort to combat international terrorism.

Seizing on a comment from Tuesday night’s Democratic debate, Mr. McCain, the presumed Republican presidential nominee, said that Mr. Obama’s plan to rapidly withdraw American troops from Iraq would leave the country in the hands of Al Qaeda and possibly other terrorist groups.

In response to a hypothetical question at the debate, Mr. Obama said that although he intended to withdraw American forces as rapidly as possible, he reserved the right to send troops back in “if Al Qaeda is forming a base in Iraq.”

Mr. McCain pounced on the remark. “I have some news,” he said at a town hall-style meeting in Tyler, Tex. “Al Qaeda is in Iraq. It’s called ‘Al Qaeda in Iraq.’ My friends, if we left, they wouldn’t be establishing a base. They’d be taking a country and I’m not going to allow that to happen.”