A week and a half ago things looked good for Romney. He was ahead in several polls including the consolidated ones like Real Clear Politics and was gaining. A week ago things started looking bad. Romney was dropping and Obama was gaining. Even then, Obama was below 50% in the swing states. If the undecideds followed the historic pattern and broke for the challenger then Romney would still win.
It didn't happen that way. The undecideds broke for Obama. It had been assumed that Democrats would be less enthusiastic than Republicans and turn out in fewer numbers. That didn't happen either. Obama managed to close the enthusiasm gap.
One big factor was Hurricane Sandy. Presidents almost always get a popularity boost immediately after a disaster. Obama's approval rating had been below 50% for some time but it climbed above 50% right after the hurricane hit, matching his percentage of the vote.
So that is why he won a close election. The bigger question is why the election was that close in the first place and what Republicans can do about it in the future.
The economy should have been a deciding factor. Obama mismanaged the recovery but there was a recovery. Voters tend to judge incumbents on how the economy is doing at the end of his term compared with the beginning. There is no question that the economy has improved. It should have been much better but voters don't seem to judge against that.
The Republicans' social agenda hurt them. Two different Senatorial candidates got caught making stupid statements about abortion and rape. Santorum, one of the last challengers for President is on the record as being against birth control. Heck, Santorum is so extreme that I would have voted for Obama over him.
It is hard to reconcile a platform of limited government with intrusive right-to-life positions. The Republicans need to learn the lesson that the Democrats learned on gun control. After Clinton waged a multi-year assault on guns, it was assumed that Gore would be even worse. There are a lot of gun owners who vote for gun rights first. Clinton's gun control probably cost Gore the election. Since then the candidates have been silent on gun control. Obama even disavowed his earlier position on outlawing guns.
Republicans need to take a similar approach. Extreme pro-life Republicans pull down the entire party. A huge majority of the country feels that abortion in the case of rape and incest should always be allowed so any candidate who suggests otherwise is wildly out of step. It gets worse when god gets dragged into it.
Gay marriage is another issue that the Republicans would be better off silent about. Again, it does not go with the limited government approach. Obama stirred up a lot of excitement by announcing that he no longer objected to gay marriage although he would not do anything to advance it. Republicans should take a hands-off approach to it.
Finally, they may need to throw Grover Norquist under the bus. I know all of the arguments against raising taxes. They are all intellectual. "Make the rich pay a little bit more" and "Make the rich pay their fair share" are emotional appeals. If Republicans are in control then taxes will not be raised. But, in order to take control, they may need to make some populist compromises. Reagan could run on a platform of tax cuts for all because a larger portion of the population was paying income tax then and, because of runaway inflation, the amount going for taxes kept increasing due to high inflation. Those factors are not present today so that platform will no longer work.
One thing that the Republicans have going for them - in the last 50 years, Obama was the only person elected president who had not been Vice President or a governor and that was a special case (Palin was the only governor on the ticket). The Republicans now have a record 30 governors. That gives them a deep pool of talent to draw from. The Democrats are short on superstars for 2016. If the Republicans can tame their social conservative side then they have a good shot at retaking the White House.