History's verdict on David Cameron, who stepped down as Britain's prime minister on Wednesday, is likely to be harsh. By calling a referendum on Britain's membership in the European Union, it will be said, he gambled the country's prosperity for partisan political advantage. What's worse, he lost — and history has no sympathy for losers.

Cameron did gamble, he did lose and the consequences will be serious. Even so, that verdict would be much too harsh. In important ways, Cameron was an impressive leader.

When it came to Europe, Cameron had no good options. Discontent with the E.U. runs broad and deep in Britain, as the referendum result confirmed. Planning on business as usual in U.K.-E.U. relations would have been a gamble, too, and not just for Cameron's Conservative Party.

Trying to resolve such complex matters by popular vote is nearly always unwise — representative democracy is the better model — but failing to respond to widespread disaffection is dangerous, too. A political class that sets its face against a settled majority of voters puts democracy itself in jeopardy (and by failing to register the strong anti-E.U. sentiment in their own electorates, it's a risk some European leaders are courting even now).

So Cameron miscalculated. Yet his virtues shouldn't be overlooked. He led a successful coalition government — the first of the postwar era, and an arrangement that doesn't come easily to British politics. Despite setbacks and controversy, he steered the economy to a better recovery from the crash than the rest of Europe achieved. He then defied the polls and won re-election, this time with a majority.

He can fairly claim to have modernized conservatism in Britain, giving it a more pragmatic and humanitarian slant — greatly increasing foreign aid, for example, and working to make gay marriage legal. Cameron's Tory party was pro-market, pro-enterprise, environmentally aware and socially tolerant. That's an appealing combination. At last year's Tory party conference Cameron said:

"Opportunity doesn't mean much to a British Muslim if he walks down the street and is abused for his faith. Opportunity doesn't mean much to a black person constantly stopped and searched by the police because of the color of their skin. Opportunity doesn't mean much to a gay person rejected for a job because of the person they love. It doesn't mean much to a disabled person prevented from doing what they're good at because of who they are. I'm a dad of two daughters — opportunity won't mean anything to them if they grow up in a country where they get paid less because of their gender rather than how good they are at their work. The point is this: You can't have true opportunity without real equality. And I want our party to get this right."

No standard-issue Tory, he got a standing ovation.

Cameron's career ended in failure, but let the record also show: He changed British politics, and for the good.

FROM AN EDITORIAL ON BLOOMBERG VIEW