When President Trump left Washington, D.C., this week for his second summit with North Korean leader Kim Jong Un, his former lawyer, Michael Cohen, was unleashing sordid allegations against Trump during his testimony to the House Oversight Committee. The president desperately needed a change of narrative, not to mention a foreign-policy win.

And yet in the end, Trump walked away in Hanoi. The man who bragged about his superior abilities to cut deals walked out on the leader he had spent the past year praising as one of his best friends on the world stage. But in doing so, Trump might have built even more credibility for the next round of negotiations.

Before coming to Vietnam, Trump seemed to need a big enough win to justify the second summit. Critics took aim at Trump for holding his first meeting with Kim without first negotiating commitments for denuclearization. That raised the ante for Trump and increased the pressure to make concessions and to leave Hanoi with a political win. Indeed, many expected Trump to get any kind of a deal he could in order to overshadow the scandals back home and set up his 2020 campaign. For instance, former U.N. Ambassador Susan Rice wondered in a New York Times op-ed if Trump could restrain himself from "caving to Kim." Having relied on false optimism about his relationship to Kim, Rice wrote, Trump might have to make more concessions than necessary to keep from a massive and embarrassing failure in Hanoi. That itself would "risk squandering an opportunity to make real headway on denuclearization."

Rice's postulation of the risks might sound familiar to critics of the Obama administration she served. Republicans criticized Barack Obama in the 2008 election cycle for pledging to meet with Kim's father, Kim Jong Il, as well as Iran's leadership, "without preconditions." They later charged that, in a rush to get a short-term foreign policy win, Obama's nuclear deal with Iran surrendered all of the U.S. leverage up front for vague and temporary concessions on nuclear weapons without addressing the issue of Iran's ballistic missile program at all.

Obama, of course, had argued that the benefits of direct diplomacy would be enough to justify the risks. Trump relied on a similar argument in for 2018's summit in Singapore, afterward claiming that the meeting had put an end to the threat of war with North Korea.

This time around, however, the president walked away. Trump sounded unusually gracious as the talks collapsed, calling the summit "very productive," but ultimately a dead end. "Sometimes you have to walk," Trump explained, "and this was just one of those times." A planned working lunch and signing ceremony had to be scrapped, the latter of which would have been heavily featured by the White House and Trump himself in the weeks and months to come.

What happened? The stalemate of the last several months about the definition of and steps toward denuclearization remains the biggest obstacle. "Basically they wanted the sanctions lifted in their entirety, and we couldn't do that," Trump told the press. Their offers for denuclearization were incremental and focused on "areas that are less important than the ones that we want."

Even so, Trump remained optimistic about the potential for an eventual agreement and about his negotiating partner. Kim "has a certain vision and it's not exactly our vision," he commented, "but it's a lot closer than it was a year ago." The talks ended on a friendly note, Trump insisted. "We shook hands," he told reporters, adding, "there's a warmth that we have now. I hope that stays. I think it will."

If so, the opportunity still exists for a later breakthrough if Trump and Kim can agree on a step-by-step plan to produce real and verifiable concessions. Perhaps Kim came to Hanoi with the same assumptions that Trump's critics made — that he needed a foreign-policy win badly enough to consider out-of-the-box proposals to get it, not just to overshadow the scandal back home, but to make an argument for his re-election campaign in 2020. By hanging tough, Kim might have assumed that Trump would cut any kind of deal just to get to the signing ceremony.

By walking away from the table, Trump has established more credibility in this relationship and in future talks. It will certainly surprise Trump's domestic critics, and perhaps it will surprise Kim enough to recalculate what he's willing to concede the next time the two meet. Trump made it clear that a bad deal is worse than no deal at all, and that may produce a better working environment — both in Pyongyang and in Washington.