During the 2012 congressional elections, Democratic candidates for the House of Representatives received a majority of the total popular vote, but Republicans retained their substantial majority of seats in the House of Representatives.
How is this possible? The main reason is gerrymandering — drawing of congressional district boundaries so as to give one party an advantage. Republicans and Democrats both do it. What’s possibly the weirdest district in the United States—Maryland’s third—was drawn to benefit a Democratic incumbent. But at the present time it is Republican gerrymandering that has skewed the congressional election results the most.
Another factor is the creation of districts in which minority groups are in the majority, so as to make sure minorities are represented in Congress. This means African-American and Hispanic voters, most of whom usually vote Democratic, are concentrated in just a few districts. The Democratic Party would be better off if African-Americans and Hispanic voters were distributed over more districts, where their votes could be combined with the votes of non-Hispanic white liberals.
To my mind, this is just as bad as a Presidential election in which one candidate gets a majority of the popular vote, but another gets a majority of the electoral vote.
It will be hard to correct his on the state level. No party that is in power will voluntarily reduce its chances of winning elected office. The answer will have to be a grass-roots movement to amend state constitutions to allow for non-partisan commissions and court review of district boundaries, based on objective criteria for compactness and respect for historic jurisdictional boundaries. You probably could program a computer to draw up congressional districts, and do a better job than now.
Until the gerrymandering problem is addressed, I think it would be a bad idea to change Electoral College representation as as Maine and Nebraska have done so that all but two electors are chosen by congressional district  instead of statewide. If that had been in effect, Mitt Romney would have carried Pennsylvania and Ohio even though Barack Obama won a majority of the popular vote there.
Click on Why Americans Actually Voted for a Democratic House for an explanation of how gerrymandering distorted the 2012 election result.
Click on Narrowing In on Absurd Gerrymanders for an explanation of how GIS software is used to gerrymander congressional districts, and how it could be used to create fair districts.
Click on The Redistricting Game for a report on a computer game that shows how gerrymandering works.
Click on America’s Most Gerrymandered Congressional District for background on Maryland’s Third District.
 A state has electors equal to the number of Senators and members of the House of Representatives. Maine and Nebraska choose two electors on a statewide basis and the rest from each of the congressional districts. All other states give all their electoral votes to the candidate that wins the statewide popular vote.
[Afterthought 11/15/12]. I admit it is possible that, even if the congressional districts were drawn in a rational non-partisan fashion, it is still possible for one party to win a majority of congressional districts and another party to win a majority of the total popular vote, depending on how the vote is distributed.