The American voting system is such that the popular vote does not always win the election. Under the US constitution, each state is given a number of electoral votes in rough proportion to its population. The candidate who wins 270 electoral votes - by prevailing in the mostly winner-takes-all state contests - becomes president. California, for example has 55 electoral college votes which are all awarded to the candidate who gets the majority of votes. There are a few states (don’t ask me which) that operate proportional representation i.e. they split their votes according to the number of actual votes each candidate receives.
The predictions were that it would be a close call, in the end Barack Obama won 303 electoral college votes against Mitt Romney’s 206 with Florida's 29 electoral votes still undecided. The president held the White House by assembling solid Democratic states and a number of important swing states such as Colorado, Iowa, Pennsylvania, Michigan, Minnesota, Virginia and Wisconsin. His narrow victory in Ohio, a critical Mid-Western swing state, sealed the victory.
Meanwhile, Republicans have maintained their control of the House of Representatives whist it looks like the Democrats will retain control in the Senate.