The world now has about 20,000 nuclear weapons; there were once 65,000. It must be counted as a major miracle of the modern age that in the 59 years since Hiroshima and Nagasaki none of them has been used in anger. With hindsight, history may conclude that the major threat facing the United States -- and the world -- in 2004 was not the war in Iraq or the immediate danger of terrorism. It was the impending breakdown of the global system that for six decades kept nuclear holocaust at bay.

Put differently: Despite this campaign's focus on Iraq and terrorism, the next president's major foreign policy problem may involve what can be done about Iran and North Korea.

North Korea already claims to have nuclear weapons; estimates are from six to eight, though the claims and estimates could be wrong. Iran denies pursuing nuclear weapons, but its denials are doubted by outside experts and undermined by Iran's incomplete compliance with nuclear inspections.

There are now eight nuclear powers: the United States, Russia, China, India, Pakistan, Israel (suspected), Britain and France. The danger is not mainly increasing that number by two. It is that if North Korea and Iran gain nuclear weapons, other countries -- possibly many of them -- would ultimately go nuclear. Then, every nuclear danger would rise dramatically: miscalculation, preemptive attacks, theft, a global market in weapons technology, and use by terrorist groups.

Since the 1950s, a two-part system has prevented nuclear horror.

The first is "mutual assured destruction." The Americans and Soviets didn't attack each other, because both knew they faced annihilation. Over time, other safeguards (the Washington-Moscow "hotline," for example) emerged to minimize miscalculations. One side effect was that, aside from Britain and France, few advanced countries that could have developed nuclear weapons did so. Most lived under the U.S. nuclear umbrella. If they were attacked, they knew (or thought) the United States would retaliate.

The second pillar is the 1968 Nuclear Non-Proliferation Treaty (NPT). This now commits five major nuclear powers (the United States, Russia, China, Britain and France) not to transfer weapons technology to other countries. All other signatories, numbering more than 170, disavow nuclear weapons and permit inspections by the International Atomic Energy Agency. North Korea and Iran signed the NPT; India, Pakistan, Israel and Cuba did not.

If North Korea and Iran go nuclear, this system would be in tatters. The NPT would seem toothless, and the residual self-restraint of "mutual assured destruction" might evaporate.

Would Japan (or South Korea) trust the United States to retaliate against North Korea? Doubts might inspire Japan (or South Korea) to go nuclear. Would Indonesia, Asia's third-largest country, want nuclear weapons? If Iran went nuclear, would Turkey, Egypt or Saudi Arabia follow suit? Would Europe want a bigger nuclear arsenal? The point: If North Korea and Iran permanently go nuclear, we will cross a threshold with unpredictable and frightening consequences.

Unfortunately, it's unclear how we can prevent this. Airstrikes can no longer eliminate North Korea's nuclear weapons because, as Nicholas Eberstadt of the American Enterprise Institute says, "we don't know where they are." Military strikes might have worked in the early 1990s (eliminating the capacity to produce weapons), but the risk was that North Korea would attack South Korea.

In their book "Crisis on the Korean Peninsula," Michael O'Hanlon and Mike Mochizuki report that the North Korean military has 1.1 million troops; 12,000 artillery pieces, 500 of which can hit Seoul; 500 ballistic missiles; 20 tunnels under the South Korean border; and 5,000 tons of chemical weapons. "North Korea would probably begin any war with a massive artillery barrage of South Korean and U.S. positions . . . and likely of Seoul itself," they write. "Chemical weapons might well be used."

American airstrikes -- or perhaps Israeli -- might destroy Iran's bomb-making capabilities. But at what cost? Iran might retaliate by sponsoring anti-U.S. terrorism. After an attack or economic sanctions, it might curb oil production.

It's not obvious (to me, at least) whether George Bush or John Kerry could best handle the nuclear threat. Britain, France and Germany have urged Iran to abandon plans to enrich nuclear fuel (from which bombs can be made) in return for assured fuel supplies for its reactors and pledges of economic aid. Kerry has endorsed such an approach, and the Bush administration has backed it, through skeptically. Kerry might work better with the Europeans and Iranians (whom he hasn't labeled part of the "axis of evil''). The case for Bush is that he's scarier. Iran might accept a diplomatic solution if it stood to lose its nuclear facilities through airstrikes.

On North Korea, O'Hanlon and Mochizuki suggest a similar bargain. North Korea surrenders its weapons and submits to inspections; in return, it receives security guarantees from the United States, diplomatic recognition and economic aid. The idea is to bribe a country from going nuclear. Operating on that theory, the Clinton administration signed a less far-reaching agreement with North Korea in 1994, but the North Koreans ultimately cheated. None of these bargains will work if either country's true aim is to possess nuclear weapons and not simply use them as negotiating chips.

Bush and Kerry haven't debated these issues in detail, because each realizes that the victor's practical choices are bleak. If there's any hope, it lies in this paradox: A country with nuclear weapons enhances its power enormously -- and its chances of annihilation. The next president must somehow convince the North Koreans and Iranians that they are taking themselves, and everyone else, down a path of madness.