While running for office, Donald Trump repeatedly blasted the Iran nuclear deal, calling it "the worst deal ever negotiated." Recently, however, his administration reluctantly acknowledged that Iran is complying with its obligations under the deal, which require it to halt its development of nuclear weapons in order to avoid further international economic sanctions.

As the Trump administration struggles to find a plan for dealing with North Korea's nuclear program, it can take several important lessons from the success of the Iran deal.

Most fundamentally, Trump and his team should reassess the relative merit of diplomatic and military strategies. Trump has already shown a clear preference for a muscular approach to foreign affairs. In his first 100 days Trump has given the Pentagon "total authorization" to conduct military operations, escalated the war on terror, conducted a missile strike on Syria, and sent a carrier strike group to put pressure on North Korea.

But although the appeal of military force is understandable given America's overwhelming advantage on the battlefield, the most challenging problems facing the United States are not amenable to military solutions. Military leaders have made clear, for example, that airstrikes would only slow down, not stop, Iran's development of nuclear weapons. A full-scale invasion of Iran, on the other hand, would be a reckless decision, ensuring thousands of casualties and plunging the Middle East yet deeper into chaos.

North Korea, like Iran, is a situation that cannot be resolved through military means. Not only would an attack on North Korea risk the use of nuclear weapons; it could also provoke the North to unleash its conventional artillery on the vulnerable civilian population of South Korea, millions of whom live within striking range. In both cases, the conclusion reached by both the Bush and Obama administrations was that strategic patience and diplomacy were the only real options on the table.

A second lesson the administration should glean from the Iran deal is that an imperfect diplomatic solution is better than no solution. Even as he admitted Iran was living up to its end of the deal, Secretary of State Rex Tillerson complained that the deal itself was a failure because it would only slow, not stop, Iran from acquiring nuclear weapons.

The real issue here is not the failure of diplomacy. No agreement can provide complete assurance about the future. The underlying issue is an inability to accept that sometimes the United States, despite being the world's sole superpower, cannot get everything it wants. The Iran nuclear deal was not a panacea, but the United States is better off with it than without it.

A final takeaway from the Iran nuclear deal is that diplomacy is actually quite popular. After all his hawkish rhetoric on the campaign trail about Iran, and after all the saber-rattling on North Korea, Trump may worry that his supporters will abandon him if he pursues a diplomatic solution. The polls, however, suggest just the opposite. Despite Trump's continual criticism of the Iran deal, a Morning Consult poll recently showed that the deal has higher support (56 percent) now than it ever did under Barack Obama. Critically for Trump, a majority of Republicans (53 percent) now supports the deal for the first time. This shows that there is room for Trump to maneuver when it comes to diplomacy and nuclear proliferation, even with a "rogue state" like North Korea.

Moreover, the polls also make clear that the public sees diplomacy as the more attractive option. According to a CBS News poll, 62 percent of the public is "uneasy" about Trump's current approach to North Korea. At the same time, the poll finds that 61 percent of the public believes that North Korea's nuclear program is a threat that the United States can contain, as opposed to just 27 percent who think military action is required.

There is no viable military option to resolve the nuclear issue in Iran or North Korea. Meanwhile, the public heartily supports diplomacy. Fortunately, reports suggest that Trump is indeed looking for a diplomatic solution on North Korea. As the Pentagon's top commander in the Pacific, Adm. Harry B. Harris Jr., told the House Armed Services Committee, "We want to bring Kim Jong Un to his senses, not to his knees."

If true, this will be welcome news. But Trump's bluster and threats have the potential to derail even a genuine desire for peaceful resolution.

A. Trevor Thrall is a senior fellow for the Cato Institute's Defense and Foreign Policy Department and an associate professor at George Mason University's Schar School of Policy and Government.