AT THE very last moment, and just before his 50th birthday this week, Barack Obama got the deal that raised the debt ceiling by between $2.1 trillion and $2.4 trillion and so prevented the United States from going into default on his watch. But this does not mean that the roof is not still in danger of falling in on his presidency. The superstar of 2008, who once looked like a shoo-in for re-election, now appears extremely vulnerable. Despite talk that he will raise a record $1 billion war chest, Democrats in Congress have begun to whisper that Mr Obama's fading chances of winning a second term are coming to depend on the absence—so far—of an exciting Republican challenger.

Single events seldom determine the fate of a presidency. Those who said just over a year ago that the oil spill in the Gulf of Mexico would doom Mr Obama were as wrong as those who thought May's killing of Osama bin Laden would make him unbeatable. The debt fight is in similar danger of being over-interpreted. Mr Obama's fate depends more on two big bets he placed well before the Republican capture of the House in November's mid-terms. The health-care reform that chewed up political capital in his first two years tanked with voters, and more than $800 billion of stimulus spending has so far failed to deliver the hoped-for growth in jobs. The outcome of the next election will depend more on unemployment than on Mr Obama's handling of the past month's comic opera on the debt ceiling.

Mr Obama says that with the debt fight behind him he can now pivot back to jobs. But the comic opera has meanwhile crystallised doubts about the quality of his leadership. After all, the Republicans won this round, even if they did not win everything they wanted. For example, the debt ceiling has been raised by enough to see the country through the far side of the coming election, without another nail-biting stand-off in between. But on the core principle that Mr Obama chose to put at the centre of the fight—the need, for fairness's sake, to tackle the deficit with tax rises on the rich as well as spending cuts—it was he who gave way.

The president, it is true, did not lose the fight because he lost the argument. He lost because he was not willing to be as reckless as the Republicans. Increasing the debt ceiling is a routine operation that allows the government to pay the bills Congress has already run up. By refusing to raise it unless they got their spending cuts, the Republicans in effect pointed a pistol at the economy and threatened to pull the trigger if they were denied. An alarming number of them sounded crazy enough to carry out this threat. Faced with the danger of a default, Mr Obama and his party had little choice but to surrender. And at least the terms of surrender include the creation of a new joint congressional committee that might, in theory, include tax increases as well as spending cuts when it produces the next slice of deficit reduction.

The troubling question is why Mr Obama fell into this trap in the first place. Could he not have made raising the debt ceiling a condition of extending the Bush-era tax cuts last December? And why did he take so long to show that he cared about putting America's finances in order? He went to the trouble of creating a bipartisan deficit commission, which at the end of last year produced just the sort of “balanced” approach he says he favours. But he then declined either to endorse its findings or present a serious plan of his own. This gave the initiative to the Republicans, who now say, plausibly, that without their brinkmanship there would still have been no start on bringing the debt under control.

Critics in his own party say that the president then added a sin of commission to his sin of omission. When the Republicans pointed that metaphorical pistol at the economy, Mr Obama could have made a bigger ruckus about this use of extortion. But he chose instead to plunge in, seduced by the chimera of a “grand bargain” with John Boehner, the Republican speaker. In the end, Mr Boehner left the president waiting at the altar—but not before Mr Obama's eagerness for the bargain had endowed the idea of haggling over the debt ceiling with a legitimacy it did not deserve.

A generous review of the story is that Mr Obama staved off default while positioning himself in the coveted centre of politics from where elections are won. He did not get his way this time, but his calls for the rich to share more of the burden by paying higher taxes will resonate with voters when he seeks re-election.

Maybe. But the public in America, and the wider watching world, saw only a mess. Meanwhile plenty of Democrats on the left grumble privately that the president's handling of the crisis has been inept, spineless—and all too typical. Having failed to take evasive action, he showed no bottom line once lured into negotiation. In the health-care negotiation, likewise, he had wasted precious time hoping for Republican support that never came. It all fits into a pattern, they say, of a leader who shies away from necessary conflict, refuses to understand the intransigence of his enemies, would rather split differences than make a firm stand and lacks the courage of his own convictions. Foreigners—from Vladimir Putin (who this week called America a “parasite”) to the Taliban—are in danger of drawing the same conclusion.

Any assessment of Mr Obama needs to acknowledge that when he was elected he inherited the in-box from hell: a financial collapse, a prostrated economy, two wars. Now he faces the opposition from hell: a reckless, populist Republican Party whose moderate voices have been silenced by ideologues and which has made throwing him out of office its foremost priority. For these tribulations he deserves a degree of sympathy. But Americans want their presidents to be winners, not victims. If he expects another term, Mr Obama is going to have to raise his game—especially if the Republicans find that candidate.

Economist.com/blogs/lexington