The British Parliament in central London on June 24. (Glyn Kirk/Agence France-Presse via Getty Images)

WHAT NOW for Europe? After Britain’s vote to exit the European Union, European leaders will be tempted to keep the rest of the E.U. together by making an example of the continent’s second-largest economy. In fact, insisting that Britain’s exit be unnecessarily difficult would lead to more economic pain for all.

Start by remembering why a generation of leaders built organizations such as the E.U. Nation-states have come together in international institutions to make their conduct regular and predictable, which promotes the free flow of goods, money, people and ideas and the wealth-creation that follows. Over the past 70 years, these institutions have been remarkably successful, keeping the peace in much of the world and setting conditions for an unprecedented growth in prosperity.

But such institutions are always imperfect, because it is exceptionally difficult to get independent countries to agree on common rules. They are always subject to exaggerated criticism, because the benefits of cooperation inevitably require some surrender of sovereign control. It takes brave leadership, of the sort Prime Minister David Cameron lacked when he agreed to hold a referendum, to explain the benefits and defend against demagogic attacks on the hated “status quo” or shadowy “elites.”

Now, if leadership continues to be lacking, we may learn that such institutions are far easier to dismantle than they are to build. Scotland and Northern Ireland, where majorities voted to stay in Europe, may decide to leave the United Kingdom. Other restive provinces in Europe (such as Catalonia) will seek to break up other nations. Meanwhile, France, the Netherlands and other countries will debate following Britain out of the E.U.

Can all this be accomplished cheerfully, with a happy nod to returning democratic control closer to the people and no price to pay? Possibly. But anyone passingly familiar with European history of the past century knows that, when relations between even seemingly enlightened countries breach, very dark forces can take control. Some voters Thursday may have been motivated by a carefully researched resentment of Brussels-imposed regulations, but others were moved by more emotional fears of refugees and other foreigners. Unscrupulous leaders are exploiting similar anxieties from France to Poland and in between.

Managing the U.K.’s demand for a divorce will be a complex task, with implications for the whole world economy. Whoever leads Britain after Mr. Cameron must strive to keep the country as interconnected with Europe as possible, following the model of Norway or Switzerland. Europe, in turn, must resist the understandable urge to punish a country that has just spurned it, and allow a graceful exit. Europe has tried the alternative path of unrestrained nationalism, escalating rounds of retributive economic policy and the autarkic misery that resulted.

Donald Trump’s substance-free railings against “stupid” trade deals and free-riding allies echo the appeal to voters’ suspicions that prevailed in Britain. Brexit’s success should offer one more argument against complacency to those who fear Mr. Trump’s appeals to bigotry. But no precise analogies can be drawn between Europe and the United States, nor between Mr. Trump and the Brexiteers. Americans still have an opportunity to make their own decisions and write their own history.