William J. Perry, founder of the William J. Perry Project on the threat of nuclear weapons, was U.S. defense secretary from 1994 to 1997.

In 1994, when I was secretary of defense, we came perilously close to a second Korean War because of North Korea’s nuclear program. Today we are again approaching a crisis with North Korea, and again the cause is its nuclear program. A war in 1994 would have been terrible, but we were able to avoid it with diplomacy (the Agreed Framework, from which the United States and North Korea withdrew in 2002). Today a war would be no less than catastrophic, possibly destroying the societies of both Koreas as well as causing large casualties in the U.S. military. It is imperative that we employ creative diplomacy to avert such a catastrophe.

The pressure boiled over this past week when Kim Jong Un announced plans to test an intercontinental ballistic missile (ICBM) that could deliver a nuclear warhead to the continental United States. In reply, President-elect Donald Trump tweeted, “It won’t happen,” seemingly suggesting he might take military action against North Korea’s missile program.

The threat is real enough. North Korea has built more than a dozen nuclear bombs and conducted five nuclear tests, several at about the destructive power of the Hiroshima bomb. Pyongyang also has a robust ballistic missile program — it has fielded a large number of medium-range missiles and is testing long-range missiles.

So the question is not whether but when Pyongyang will have a nuclear-armed ICBM. Its ICBM program is not yet operational, and it must take many difficult steps to make it so. But this is evidently a high-priority program moving at a fast pace. There is no reason to doubt that it will reach an operational capability, perhaps in the next few years.

Certainly this is dangerous, but we should try to understand the nature of the danger. During my discussions and negotiations with members of the North Korean government, I have found that they are not irrational, nor do they have the objective of achieving martyrdom. Their goals, in order of priority, are: preserving the Kim dynasty, gaining international respect and improving their economy.

The regime has demonstrated — over and over again — that it is willing to sacrifice its economy to assure that the dynasty is preserved. During negotiations in 1999 and 2000, we found a way to achieve all three of their goals without nuclear weapons. I believe that the North Korean government was ready to accept our proposal (it is easier for leaders to forgo weapons they do not yet have), but we can never be certain of that — nor that they would have, in fact, complied with an agreement — because the George W. Bush administration cut off the talks in 2001.

I believe that the danger of a North Korean ICBM program is not that they would launch an unprovoked attack on the United States — they are not suicidal. But they have been playing a weak hand for decades, and they have demonstrated a willingness to take risks in playing it. The real danger of their ICBM program is that it might embolden them to take even greater risks — that is, overplay their hand in a way that could (inadvertently) lead to a military conflict with South Korea. The South Korean military, backed by U.S. air and naval power (and a small ground force), is more than a match for the large but poorly equipped North Korean military. So if North Korea were to begin losing a conventional conflict, they might in desperation turn to their nuclear weapons.

What can we do to mitigate that danger? During the time I was defense secretary, I considered a preemptive conventional strike on their Yongbyon nuclear facility. We rejected that option in favor of diplomacy. Such a strike could still destroy the facilities at Yongbyon but probably would not destroy their nuclear weapons, likely not located there. In 2006, Ashton B. Carter, now secretary of defense, and I recommended that the United States consider a strike on North Korea’s ICBM launch facility. I would not recommend either of those strikes today because of the great risk for South Korea; at the very least, any such plan would have to be agreed to by South Korea’s leadership, since their country would bear the brunt of any retaliatory action.

I believe it is time to try diplomacy that would actually have a chance to succeed. We lost the opportunity to negotiate with a non-nuclear North Korea when we cut off negotiations in 2001, before it had a nuclear arsenal. The most we can reasonably expect today is an agreement that lowers the dangers of that arsenal. The goals would be an agreement with Pyongyang to not export nuclear technology, to conduct no further nuclear testing and to conduct no further ICBM testing. These goals are worth achieving and, if we succeed, could be the basis for a later discussion of a non-nuclear Korean Peninsula. These objectives are far less than we would desire but are based on my belief that we should deal with North Korea as it is, not as we wish it to be.

If this attempt at diplomacy fails, then we could consider much more punishing sanctions that would require China’s significant participation. That would be more likely if North Korea rejected a serious diplomatic approach. We could also pursue non-diplomatic approaches, such as disrupting their ICBM tests, not at their launch sites but over international waters. Indeed, our diplomacy would have a better chance of working if the North Korean government realized that we were serious about non-diplomatic alternatives.

Time is of the essence. If we don’t find a way — and soon — to freeze North Korea’s quest for a nuclear ICBM, this crisis could all too easily spin out of control, leading to a second Korean War, far more devastating than the first.