President Bush and John F. Kerry clashed over the Iraq war Thursday night in an intense and substantive first debate, in which the Democratic nominee charged that the war was a diversion from the more important war against al Qaeda and the president defended the conflict as crucial to the nation's security.

In their first face-to-face encounter, the two presidential candidates repeatedly returned to the themes that have dominated the campaign. The Massachusetts senator accused the president of "misleading" the nation as he went to war, while Bush said nine times that Kerry's "mixed messages" and "mixed signals" mean he does not have the steadiness to be an effective commander in chief.

"The president has made, I regret to say, a colossal error of judgment, and judgment is what we look for in the president of the United States of America," Kerry said of the war. "I would not take my eye off of the goal: Osama bin Laden."

Bush countered that Kerry's criticism of the war in Iraq would make it impossible for him to lead allies to victory there. "What's the message going to be: -- Please join us in Iraq for a 'grand diversion'?" Bush asked. Allies, he said, "are not going to follow somebody who says this is the wrong war at the wrong place at the wrong time. They're not going to follow somebody whose core convictions keep changing because of politics in America."

There were no glaring mistakes by either candidate during the 90-minute debate at the University of Miami, although Bush often appeared agitated, scowling at times as Kerry leveled his charges. While both delivered their messages forcefully, Kerry sharply questioned the president's credibility and highlighted his own ability to serve as commander in chief.

It will take days to see how the millions of American viewers reacted to the debate, but instant polls by the major networks, subject to less rigorous methodology than the high-profile campaign polls, showed Kerry had significantly outperformed Bush. The Democrat was hoping a strong performance would reduce the narrow but consistent lead Bush has had in opinion polls nationally and in key electoral states.

Both men appealed to the widespread fear and unease in the nation by suggesting his opponent would be a more dangerous choice. Bush reminded viewers of the menace of foreign terrorists. "We are facing a group of folks who have such hatred in their hearts, they'll strike anywhere with any means," he said, also arguing that "the biggest disaster that could happen is that we not succeed in Iraq."

Kerry, by contrast, painted an ominous portrait of Iraq: "We see beheadings, and we got weapons of mass destruction crossing the border every single day, and they're blowing people up." He suggested Americans have more to fear at home. "Ninety-five percent of the containers that come into the ports, right here in Florida, are not inspected," he said. "Civilians get onto aircraft and their luggage is X-rayed, but the cargo hold is not X-rayed. Does that make you feel safer in America?"

The candidates hewed to their well-known styles. Kerry cited many statistics and used sometimes elaborate arguments to make his point. The president frequently employed slogans from his campaign stump speech and often put Kerry on the defensive by shifting from questions about his own record to questions about Kerry's capabilities.

When Bush, responding to a question about Iraq, said "the enemy attacked us," Kerry called Bush's remark "extraordinarily revealing" and added: "Saddam Hussein didn't attack us; Osama bin Laden attacked us."

"Of course I know Osama bin Laden attacked us," Bush replied.

Bush repeatedly talked about how hard the war was, and spoke most passionately about praying and crying with the wife of fallen soldier. "I told her her husband's sacrifice was noble and worthy, because I understand the stakes in the war on terror," he said. "Every life is precious."

Kerry, who has been criticized by a group of Vietnam veterans for leading antiwar protests and talking about how U.S. soldiers committed war crimes, said his experience in the early 1970s taught him to speak out in troubled times. "It reminds me it is vital for us not to confuse the war -- ever -- with the warrior. That happened before," he said. Kerry sought to turn the president's laserlike focus on consistency against him. "It is one thing to be certain. But you can be certain and be wrong."

The debate revisited many of the well-known disagreements from the campaign and repeatedly returned to its central themes: Kerry doubting Bush's "credibility" at home and abroad, and Bush repeatedly doubting Kerry's ability to command and not "waver."

Kerry suggested that Bush could have captured bin Laden. "We had him surrounded, but we didn't use American forces, the best-trained in the world, to go kill him," Kerry said. "The president relied on Afghan warlords that he outsourced that job to."

As he often does on the stump, Bush ridiculed Kerry's vote against a spending bill for Iraq and Afghanistan and the Democrat's explanation that he voted for it "before I voted against it." "That's not what a commander in chief does when you're trying to lead troops," Bush said.

Kerry ceded the point but sought to portray Bush's errors as greater, saying: "I made a mistake in how I talk about the war, but the president made a mistake in invading Iraq. Which is worse?" He added: "I believe that when you know something's going wrong, you make it right. That's what I learned in Vietnam. . . . And I'm going to lead those troops to victory."

Both candidates caricatured and exaggerated each other's positions. But the debate, coming after a campaign full of attack ads and bitter disputes about each man's service during the Vietnam War, was relatively high-minded and substantive. The two did not strongly question each other's character, and even took time to praise each other, Bush noting Kerry's relationship with his daughters and Kerry offering kind words for the first lady.

Kerry portrayed Hussein as a lesser threat than al Qaeda. "The president moved the troops so he's got 10 times the number of troops in Iraq than he has in Afghanistan, where Osama bin Laden is," he said. "Does that mean that Saddam Hussein was 10 times more important than Osama bin Laden? I don't think so."

Bush avoided a question about whether the country would be more susceptible to terrorist attack under Kerry -- something Bush's campaign has often done. "I don't believe it's going to happen. I believe I'm going to win, because the American people know I know how to lead," he said. "I understand everybody in this country doesn't agree with the decisions that I've made. And I've made some tough decisions. But people know where I stand."

Kerry sought to rebut Bush's charge, highly effective so far, that he "wilts" and "wavers." "I have no intention of wilting," he said. "I've never wilted in my life. And I've never wavered in my life. I know exactly what we need to do in Iraq, and my position has been consistent.

Bush retorted: "The only thing consistent about my opponent's position is that he's been inconsistent. He changes positions. And you cannot change positions in this war on terror if you expect to win."

The two frequently returned to the question of whether Bush failed to enlist allies in the war in Iraq. "I think we need a president who has the credibility to bring the allies back to the table and to do what's necessary to make it so America isn't doing this alone," Kerry said.

Kerry criticized Bush for shunning alliances. "This president has left them in shatters across the globe, and we're now 90 percent of the casualties in Iraq and 90 percent of the costs. I think that's wrong, and I think we can do better."

Bush portrayed Kerry's remarks as insulting to Britain, Poland and other nations that have contributed to the war. "I don't appreciate it when a candidate for president denigrates the contributions of these brave soldiers," he said.

Still, the candidates came across as largely agreeing on many of the key issues of the debate. Both said they would continue the war in Iraq until victory is at hand, train Iraqis to provide security and continue to press allies to provide additional assistance, especially as the January election draws near. They both promised robust programs to secure borders, ports and airlines and target nuclear proliferation as their top priority over the next four years.

The candidates disagreed most sharply on North Korea, which during Bush's term has evicted international inspectors and reprocessed enough plutonium to produce half a dozen nuclear weapons. Kerry called for bilateral talks with the North Korean government to give up its weapons. Bush blasted that idea as a "serious mistake," saying it would end the multi-nation diplomacy underway by the administration.

The candidates appeared to differ on the potential of sending U.S. troops to restore peace in Sudan, where ethnic fighting has ravaged the Darfur region. Both called the situation "genocide," and said the African Union should take the lead role in restoring order. But Kerry said the United States should commit more logistical assistance now and consider a larger role if the African Union needs it to end the bloodshed.

The debate was seen, along with each party's nominating convention, as one of the most significant events of the general-election campaign. Both parties viewed the exchange as the best -- and possibly last -- chance for Kerry to erase the narrow but consistent lead Bush has had in polls nationally and in key electoral states.

The candidates clashed for 90 minutes from twin lecterns set up in a converted basketball arena at the University of Miami. Standing on a red carpet before a patriotic backdrop, they fielded questions from moderator Jim Lehrer of PBS in an exchange governed by strict rules agreed on by the two campaigns as a way to limit surprises. The first of three debates, it was designed to cover only foreign affairs and homeland security -- which because of the 2001 terrorist attacks and the war in Iraq have replaced the economy as the campaign's main focus.

The two men sparred over Iraq policy after a particularly violent day in that country. Bombs in a west Baghdad neighborhood killed at least 34 children and seven adults and wounded scores, including 10 American soldiers. A U.S. soldier and several Iraqis were killed by car bombs outside of Baghdad and in the northern city of Tall Afar, while insurgents in Iraq attacked a support area for U.S.-led coalition forces and took 10 more hostages.

President Bush makes a point during his first debate with Sen. John F. Kerry, in which the two voiced stark differences on Iraq policy. First lady Laura Bush, left, and Teresa Heinz Kerry, wife of Democratic presidential candidate John F. Kerry, greet each other after the debate at the University of Miami.Moderator Jim Lehrer briefs the audience before the start of the debate, which was governed by strict rules that both campaigns agreed on as a way to limit surprises.