When Winston Churchill was defeated in the 1945 general election, his wife, Clementine, told him it was "a blessing in disguise". The grand old man was not convinced. He harrumphed: "At the moment, it is very well disguised." The pounding delivered by America's voters to the Democrats is a blessing in disguise for Barack Obama. The results of the mid-term elections were not at all bad for the president. I'd go further: his prospects of winning a second term look as good, if not better, than ever.

On the face of things, this is a perverse conclusion to draw after one of the worst drubbings suffered by the Democrats in many years. Resurgent Republicans gained more than 60 seats in the House of Representatives, handing them their biggest majority in that half of Congress since the 1940s. They added six Senate places, among them Obama's old seat in Illinois. Though this was not enough to give them control of the other half of Congress, it will make it that much more difficult for Democrats to overcome Republican filibusters. The Republicans also grabbed the keys to the governors' mansions in a slew of key states. Obama reacted to the defeats by ruefully observing: "Some election nights are better than others" and accepting he had taken a "shellacking" from the voters. Like Churchill, he must be inclined to think that, if this is a blessing, it is a very well disguised one.

So it is. To find the encouragement for the president, you first have to dig beneath a thick crust of inevitable headlines describing these elections in terms of a humiliating rout. Then you have to hack through a lot of predictable commentary on both sides of the Atlantic about the evaporation of the euphoria which attended Obama's election two years ago and talk about his "fall from grace". Only once you've done that do things come into perspective. It helps to have a sense of history. Heavy midterm defeats for the party occupying the White House are very common. Midterms are a safety valve which Americans often use to let off steam when they are in a discontented state. Franklin D Roosevelt took a thumping in 1938 and went on to win two more presidential elections. Ronald Reagan suffered a severe midterm defeat two years before being returned to the White House by a landslide. Bill Clinton followed a similar pattern. In his memoirs, Clinton writes: "After the 1994 elections, I had been ridiculed as an irrelevant figure, destined for defeat in 1996." As it turned out, he cruised to victory. In each case, midterm defeats galvanised the president to sharpen up his act while the other side misread what had happened.

Republicans, intoxicated by their victories, are making a major mistake. That is to confuse a protest vote against the Democrats with enthusiasm for Republicans. Some of their most prominent figures are vaingloriously bragging about heading to Washington to "take our government back" and undo everything Obama has enacted since he arrived in the Oval Office. That is a misinterpretation of the mood. In polls, 48% of voters agreed with the Republicans that Obama's healthcare reforms should be repealed. But 47% said they wanted to retain or expand those reforms. Cutting the deficit should be the priority of Congress, according to 39%; spending money to stimulate the economy is preferred by an almost equal 37%.

This election did not represent a ringing endorsement of the Republican platform. It could never be that when there wasn't anything that you could dignify with the name of programme. The ratings of Republicans in Congress are just as dire as those for Democrats – and both are a lot worse than Obama's personal ratings which remain reasonably firm. In short, America is a house divided and has now given itself a divided government.

It is true that this will have some disempowering effect on the president. He will find it much harder to drive through any landmark laws now that the Republicans have control of the House and can jam up the Senate. That makes him look even wiser to have achieved a string of legislative changes in the early period of his presidency in the face of obstructive Republicans who offered no coherent alternative of their own in the cynical hope of undermining his hopes of re-election.

By capturing the House of Representatives, the Republicans have acquired a slice of the power and a share of the responsibility for government. Responsibility is going to expose postures that are riddled with contradictions. They want a smaller government and a reduced deficit except in those many areas where they demand bigger government and more spending. They are also riven with factionalism and without an agreed national leadership. On the right, we have the traditional Republicans. On the further right, we have the Tea Partyists. The tea bags contend, and they are correct, that they energised these elections by firing up conservative activists. The establishment Republicans say, and they are also correct, that more moderate and competent candidates would have won additional seats from the Democrats which were lost because more centrist Republican candidates had been displaced by the madder hats of the insurgency. The clownish Christine O'Donnell – the first candidate for office to have to begin a campaign ad with the declaration: "I'm not a witch" – lost a Senate seat that should have been won for the Republicans in Delaware.

Sharron Angle, another Tea Party favourite who had claimed that American cities were run by sharia and thought Hispanic voters would find it appealing if she told them they looked like Asians, lost to Harry Reid, the Democrat Senate majority leader who had earlier seemed doomed to defeat. In those races were further encouraging auguries for President Obama. Americans may be as mad as hell, but they are not crazy enough to want to embrace the wilder shores of Tea Partyism.

Such is the pace of democracy in America, Republicans are already obsessing over who should be their standard bearer in the next presidential contest in 2012. That is going to expose their fault lines even more starkly. Despite the rebuffing of the Tea Party in some seats, the Republicans will continue to be dragged to the right by Sarah Palin and her fellow travellers. The threat of the self-styled Mama Grizzly running for the Republican presidential nomination in 2012 terrifies the party's establishment as much as the prospect delights Democrat strategists.

The former governor of Alaska is, in some ways, a political genius. She proved to be a hopeless liability when she was on John McCain's ticket two years ago. She is an intensely polarising figure and a narcissist in love with her own shtick. Having had two years to raise her game, she continues to demonstrate an alarming lack of grip or coherence on policy. She now holds no elected office. Yet she has fashioned a profile which makes her probably the best-known American politician in the world after Obama, Bush and Clinton. Celebrity is not the same, however, as credibility. Two out of three American voters believe Sarah Palin is not qualified to be president. The very things about her and the tea baggers which excite right-wing voters are those which repel the more moderate ones.

There are two further disguised blessings for the president. Paradoxically, one is the economy. Amid the welter of analysis of the Democrats' defeats, by far the most compelling explanation is the simplest one: Americans are frustrated with a lacklustre recovery from the sharpest contraction since the Great Depression. It is not hard to divine why they are angry when the official unemployment rate is nudging 10% and the real level of joblessness is nearer 20%. If there is a double-dip, Obama is almost certainly toast. If the economy continues to limp, he will be in trouble. If the economy is clearly on the mend, the issue that so damaged the Democrats in the midterms ought to work for Obama in the next presidential election.

People in economic distress become angry people and angry people tend to be volatile people. They thwacked the Republicans in the 2006 midterms. Two years ago, Obama won the best presidential victory for a Democrat since 1964. Now he and his party have taken a bashing. The House has not changed hands and back again so quickly in many decades. Moods ebb and flow in big waves. Success goes to the sort of politician who is skilled at surfing the swells of public opinion, one who can ride the crest and also keep his balance when it breaks. Barack Obama is that sort of politician.

In the wake of the midterms, he has voiced a willingness to work with the Republicans in Congress. He will prosper by being seen as the one who attempted to compromise only to be rebuffed by a Republican party sucked into confrontationalism by its overconfident right. His original appeal was as a healing politician who could lift America above ugly partisanship. The extremism of Tea Partyism will help him to be that attractive, unifying centrist again. My money is on Barack Obama securing a second term in 2012 and quite possibly winning big. Yes, he still can.