Fannie Mae was originally created as a government entity to provide liquidity to the mortgage market. Banks that had loaned money to consumers for mortgages could sell them to Fannie Mae to get 'new' money to make additional loans. Additionally, this allowed the banks to reduce their interest risk. Fannie Mae could own the mortgages or package them and sell them as mortgage-backed securities.
Per Wikipedia: "... For a simplified example, a bank can sell one hundred $1000.00 bonds that pay 7% interest based on a mortgage loan for $100,000.00 that it made where it charged its customer 7%. The bank would therefore recoup the money lent to the homeowner, and the bond owners would effectively be lending the funds to the homeowner. The homeowner would not know this because he or she would still be receiving the bill from the bank who would pass the payments on to the bond owners (this is known as servicing the loan). Doing this solves both problems simultaneously, as the investor seeks a sure fixed interest rate at which to invest his or her money and the bank recoups its funds to lend more money. Under this model however, the investor is at risk if the borrower does not pay the monthly payment or the loan is not repaid from the sale of the house. Even though many investors might purchase bonds that are based on multiple mortgages, betting that only very few of them would have any problems, the US government sought to increase demand for these bonds (and therefore supply of mortgages, and therefore, lower mortgage interest rates) by creating Fannie Mae to guarantee the bonds. What Fannie Mae does is essentially makes any missed payments to the bondholder that the borrower misses, and also makes up for any loss for the loan not being fully repaid either by the borrower or from the sale of the house, and skims a certain percentage of the payment each month and holds the funds in reserve as insurance against these scenarios. Therefore investors believe they have no risk unless Fannie Mae itself becomes bankrupt..."
In the late 60's Fannie Mae was converted into a private, stockholder-owner corporation to get it off the government books. As time went by Fannie Mae started to engage in other practices to increase its income, and to use derivatives to hedge its cash flow. Even though it did not directly receive government funding, Fannie Mae has always benefited from an implied government guarantee (given that the Congress essentially favored it in many ways e.g. allowing Fannie Mae to maintain a capital/asset ratio much lower than other financial institutions) that has greatly lowered its cost of doing business.
The Congress has had an incestuous relationship with the two GSEs - Senators and Representatives have received significant campaign contributions; have been lobbied and 'wined and dined'; have profited from the revolving door between administrations, the Congress, and the GSE-universe (Fannie Mae, Freddie Mac, their lobbyists, etc.); etc. Fannie and Freddie have served the Congress' will all too well, making it easier to borrow and own a home, thereby increasing home ownership. The two GSEs ended up having half the U.S. residential mortgage market, or around USD 6 billion.
As long as housing prices trended upwards all was well. However, with the bursting of the subprime bubble, increasing numbers of defaults have hurt the two, causing them huge losses. Given the risk to their viability the government was forced to step in and place them under conservatorship. The risks of not doing so were too steep - if Fannie and Freddie had gone under it would have caused havoc, for example hurting families' savings, their ability to get home and auto loans, etc. Additionally, pension funds, state and municipal entities, as well as many foreign governments have been big purchasers of their mortgage-backed securities, and defaults would have a huge ripple effect (as well as leading to a loss of confidence in the U.S. economy and U.S. government that could be catastrophic given that the U.S. depends on other countries to fund its deficits...)
It is amusing to see this cast (especially by the Democrats) as a morality play, with Republicans and rich fat cats responsible for feeding at the public trough and ripping off the poor middle class - that has not reaped any benefit and is now unfairly feeling the fallout in the form of a reduced standard of living. The fact is that the Democrats, in fact both parties, have always made a fetish of the middle class - at every election it's all about which party can do more for the middle class. As if via their rules, via GSEs such as Fannie and Freddy, etc. the Congress has not pushed home ownership that has greatly benefitted the middle class. For example, by enshrining the deductibility of home mortgage interest the Congress has (in financial terms) assisted the middle class by many, many orders of magnitude more than they have ever done for the poor (e.g. subsidized housing, etc.)
It remains to be seen how this will eventually play out financially - how big of a hit will the government end up taking - will taxpayers be out hundreds of billions, make a small loss, break even, or even come out positive in the long run? It will be a few years before this shakes out.
Fannie Mae homepage
Fannie Mae - Wikipedia
Fannie, Freddie: Feds Step In
Battle begins over future of mortgage giants
Freddie Mac/Fannie Mae bailout: Guess Who Wins
Fannie, Freddie taken over partly to ease foreign nerves
Fannie, Freddy rescue binds taxpayers to housing markets
Federal takeover of Fannie Mae and Freddie Mac - Wikipedia
U.S. Senate Roll Call Votes 110th Congress - 2nd Session
Roll call for the legislation that enabled the takeover of Fannie and Freddie - note that McCain, Obama, and Clinton all did not make the vote...