When he saw the exit poll on election night, 2015, on the first bong of Big Ben, he began to celebrate the first majority Conservative government for 23 years. But the successful decapitation of his coalition partners turned out to be a curse.
Without a majority, it would have been easier to postpone the EU referendum that brought him down, and blame the delay on those pesky Liberal Democrats. That chance was lost.
Instead, with the bravado that he sometimes enjoys to indulge, he pressed on. And another piece of luck turned against him. He watched the Labour Party elect Jeremy Corbyn to succeed Ed Miliband. Still unaware of how much that meant, he prepared for life after the referendum and the delicious chance to reshape his government for an extended swansong.
But Corbyn's lukewarm referendum campaign - and his unpopularity among many older Labour voters who pulsed to the Brexit message - compounded the consequences of Cameron's decision to go for a vote. And there was no way back.
He now finds himself in the unusual position of depending on his referendum arguments being proved wrong for his reputation to rise.
If recession is avoided, and Brexit seems calmer than the Cameron-Osborne stormy forecast - complete with thunder, lightning and financial pestilence - then he may be seen as a significant transitional figure who left the country strong enough to adapt to fundamental constitutional change.
If not, he will surely be considered - at least in the years immediately ahead - a prime minister whose rashness betrayed him, and as a leader too weak to unite a party still riven by the schism at the end of the Thatcher era that remains an obvious and debilitating rift, albeit a touch less ill-mannered than Labour's.
The Cameron project delivered some of the "progressive" reforms that he promised - he would cite gay marriage and the national living wage - but never stood a chance of healing a party in which many of the members didn't want those reforms.
Therefore his legacy will depend in large part on the performance of his successor. If she finds a way of negotiating a way through the Brussels thicket that can satisfy most reasonable Leave campaigners and reassure others that 40 years hasn't been thrown away for nothing, Cameron will be one of the beneficiaries.
But think of the dangers. A governing party split more painfully even than before. Financial storms stirred up by markets and businesses who don't believe the negotiation offers prosperity, and take their investment elsewhere.
Perhaps even - although there's been too much loose talk of this - an independence referendum in Scotland in two years or so, and the possibility of a Yes vote.
In those circumstances Cameron would slip fast down the prime ministerial league table.
He might find himself near the bottom of the modern ones, bumping into Anthony Eden, after whose downfall an American secretary of state said famously that Britain had lost an empire and not yet found a role.
The pervasive feeling of failure that followed Suez - much greater than the scale of the fiasco itself - could easily return.
Cameron needs a successful Brexit to prove himself wrong and - with a feeling of paradox that he will enjoy - rehabilitate his brief and explosive second term.
Behind the polished good humour of his last prime minister's question time, that is the irony that clings to him as he leaves Downing Street - his cabinet, all his powers of patronage, and his cat. He is a young man, with a career ahead of him, and he will understand well how important it is for him that the political barometer turns to "fair" in Theresa May's first year or two.
He will look, too, with mixed feelings at the Labour Party. Having been hobbled by Corbyn's unenthusiastic Euro-campaign, Cameron will now enjoy the sight of the official opposition tearing itself to pieces in a leadership election and what will certainly be a bitter aftermath, whoever wins.
And he might wonder whether, deep in the uncertainty that will accompany that process, there lies a coming political realignment that will intrigue and puzzle the centre-left for a long time to come. A change that could in time reshape his own party, too.
Because one day history may see Cameron one of the last prime ministers of his kind. Who can say, after the passions of the last month, that the two parties that have dominated our politics for nearly a century will look the same in the next generation?
He is likely to live long enough to see changes for which the last few passionate weeks, for all their drama, have only been a preparation.
James Naughtie is BBC News Book Editor and presents Bookclub on BBC Radio 4. He was a presenter on the Today programme from 1994 to 2015.
David Cameron's luck ran out at the moment of his greatest triumph.