Why and how did Barack Obama become president?

Barack Obama defeated Republican John McCain by winning the popular election on November 4, 2008, winning 52.9% of the popular vote. He was officially elected by the Electoral College on December 15, 2008. His inauguration was on January 20, 2009. Then, on November 6, 2012, President Obama won a second term in office, gaining 332 electoral votes to Mitt Romney's 206, and also winning the popular vote 51% to 48%.