President Trump’s cyber saber-rattling has reached frightening new heights in recent weeks, culminating in the tweet: “Get ready Russia, because they will be coming, nice and new and ‘smart!’ ”

We now know the “they” in the tweet was a reference to American cruise missiles launched as part of the coordinated strike against Russia-backed Syria on April 13, with the threat of further attacks should Bashar al-Assad’s regime continue to use chemical weapons against its own  people.

Shortly after firing off his bellicose warning about the missiles, Trump added, “Our relationship with Russia is worse now than it has ever been, and that includes the Cold War.”

He may just be right — and he’s a major reason why.

At the height of the Cold War, during those 13 fateful days in October 1962 when the United States and the Soviet Union tottered on the brink of thermonuclear war, the leadership and critical thinking of President John F. Kennedy and Premier Nikita Khrushchev saved the day. Both having personally experienced the horrors of war in the 1940s, they valued restraint, ultimately pulling their countries from the brink of war — and preventing the probable deaths of hundreds of millions of people around the world.

Today, however, the two countries are led by men who lack the critical traits that allowed Kennedy and Khrushchev to avoid catastrophe in 1962. Unless Trump and Russian President Vladimir Putin learn quickly from the past, they threaten to turn our current situation into a disaster.

President Trump’s public bluster stands in stark contrast to Kennedy’s reaction on the morning of Oct. 16, 1962, when he first learned that the Soviets were installing medium-range ballistic missiles (MRBM) in Cuba.

A U-2 pilot flying at 72,000 feet over the island shot 6,000 feet of film that identified missile erectors, trailers and canvas-covered objects approximately 67 feet in length — the same size as the Soviet MRBM.

Kennedy resolutely vowed to do something “to take out those missiles.” His immediate options ranged from a quick surgical strike on the missile sites to a full-scale invasion of Cuba to eliminate the missiles. Leaning toward military action, Kennedy was prepared to give approval for a U.S. military landing on the island’s shores, which would have been the largest amphibious landing since D-Day in 1944.

But he resisted the temptation to act impulsively. He realized such an operation would have dangerous ripple effects in Europe, as Soviet tanks would have undoubtedly rolled into West Berlin and the dominoes would have continued to fall from there — dominoes whose fall he might not have been able to control.

Crucially, Kennedy kept his initial bellicose musings private, sharing them only with members of ExComm (the Executive Committee of the National Security Council, which included, among others, Attorney General Robert F. Kennedy, Vice President Lyndon B. Johnson, Defense Secretary Robert McNamara and CIA Director John McCone). This prevented the president from boxing himself in by speculating publicly or stirring fervor for war that could later limit his options.

Kennedy knew that he needed the best understanding possible of the facts on the ground and of Soviet intentions. And soon new intelligence forced him to reevaluate his initial response. Kennedy’s CIA analysts explained that the Soviet MRBMs would not be operational for two weeks, allowing him valuable time to consider all other options with the goal of securing a peaceful solution.

Kennedy was the first modern-day commander in chief to have experienced combat firsthand, witnessing the deaths of two crew members when a Japanese destroyer tore his patrol boat, PT-109, in half in the summer of 1943. He understood the devastation of war, which shaped his desire to achieve a peaceful removal of the threat to the United States.

So instead of a military landing in Cuba, he agreed to impose a quarantine of the island nation enforced by U.S. warships that would, if necessary, force Soviet ships carrying nuclear missiles and materials to turn back. Some members of ExComm thought this was a weak response, but Kennedy felt that he needed to give himself and his Soviet counterpart more time to find a pathway to peace before fully deploying U.S. military might.

The episode revealed that Kennedy understood that restraint did not signal weakness. So, too, did Khrushchev.

His generals urged the Soviet premier to hold fast — not to yield an inch to America’s demands. Khrushchev asked his military men whether such a strategy would result in the deaths of 500 million human beings. The generals, according to Khrushchev, had little interest in discussing the apocalyptic body count. Instead, they worried that the Chinese or other communist nations might accuse the Soviets of appeasement or weakness.

“What good would it have done me in the last hour of life to know that though our great nation and the United States were in complete ruin, the national honor of the Soviet Union was intact?” Khrushchev later wrote.

Both leaders continued this delicate balancing act for several more days until the world nearly spiraled out of control on Oct. 27, 1962 — Black Saturday — when a U-2 pilot named Rudolf “Rudy” Anderson was shot down and killed over Banes, Cuba, by a surface-to-air missile launched by the Soviets.

That same day, another U.S. spy pilot, Chuck Maultsby, became disoriented on a U-2 flight over the Arctic Circle and ended up lost in Soviet airspace, ultimately chased by Soviet fighter jets who spotted him.

Neither Maultsby nor the Soviet troops who killed Anderson were acting on the orders of Kennedy or Khrushchev. Both incidents were miscalculations, resulting from incorrect interpretations and breakdowns of command that could easily have led to war and ultimately cost hundreds of millions of lives.

But Kennedy refused to succumb to immense pressure to act forcefully, opting instead to use every last minute to find a way to avoid more bloodshed.

Khrushchev, now worried that Kennedy would have a hard time keeping the reins on his generals, won an agreement from his own generals and advisers to dismantle their missiles, as long as the Americans promised not to invade Cuba. Kennedy in return gave the Soviet leader a victory of his own — the removal of U.S. Jupiter missiles from Turkey — something that the United States had planned to do anyway.

Both leaders had given themselves and each other the critical time and space needed to weigh all available options  to avoid catastrophe. Their courage and poise provides us with indelible lessons on leadership — lessons and warnings that Trump must heed today. The behavior of Kennedy and Khrushchev stands in stark contrast to Trump’s public bellicosity and disregard for warnings from the U.S. intelligence community about everything from Russian meddling in the 2018 midterm elections to climate change.

By impulsively tweeting about matters of war and peace — often informed by nothing more than talking heads on cable news — he leaves himself less room to maneuver and pressures his adversaries to appear tough and respond in kind. The lesson from Kennedy and Khrushchev is clear: Maintaining flexibility, publicly demonstrating restraint and using the best information available helps achieve America’s goals in a peaceful manner. Failing to do so in matters of war and peace could prove catastrophe — something Trump needs to learn before it’s too late.